Python peewee 模块,ProgrammingError() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用peewee.ProgrammingError()

项目:aiowing    作者:embali    | 项目源码 | 文件源码
def get_current_user(self):
        """Current user"""

        session = await get_session(self.request)
        email = session.get('email', None)

        if email is None:
            return None

        try:
            user = await settings.manager.get(
                User
                .select()
                .where(User.email == email))
        except (User.DoesNotExist, psycopg2.OperationalError,
                peewee.IntegrityError, peewee.ProgrammingError):
            return None

        if not (user.active and user.superuser):
            return None

        return email
项目:sentinel-old    作者:monacocoin-net    | 项目源码 | 文件源码
def check_db_sane():
    """ Ensure DB tables exist, create them if they don't. """
    check_db_schema_version()

    missing_table_models = []

    for model in db_models():
        if not getattr(model, 'table_exists')():
            missing_table_models.append(model)
            printdbg("[warning]: table for %s (%s) doesn't exist in DB." % (model, model._meta.db_table))

    if missing_table_models:
        printdbg("[warning]: Missing database tables. Auto-creating tables.")
        try:
            db.create_tables(missing_table_models, safe=True)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not create tables: %s" % e)

    update_schema_version()
项目:sentinel-old    作者:monacocoin-net    | 项目源码 | 文件源码
def check_db_schema_version():
    """ Ensure DB schema is correct version. Drop tables if not. """
    db_schema_version = None

    try:
        db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
    except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
        printdbg("[info]: Can't get DB_SCHEMA_VERSION...")

    printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
    printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
    if (SCHEMA_VERSION != db_schema_version):
        printdbg("[info]: Schema version mis-match. Syncing tables.")
        try:
            existing_table_names = db.get_tables()
            existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
            if (existing_models):
                printdbg("[info]: Dropping tables...")
                db.drop_tables(existing_models, safe=False, cascade=False)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not drop tables: %s" % e)
项目:sentinel    作者:dashpay    | 项目源码 | 文件源码
def check_db_sane():
    """ Ensure DB tables exist, create them if they don't. """
    check_db_schema_version()

    missing_table_models = []

    for model in db_models():
        if not getattr(model, 'table_exists')():
            missing_table_models.append(model)
            printdbg("[warning]: table for %s (%s) doesn't exist in DB." % (model, model._meta.db_table))

    if missing_table_models:
        printdbg("[warning]: Missing database tables. Auto-creating tables.")
        try:
            db.create_tables(missing_table_models, safe=True)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not create tables: %s" % e)

    update_schema_version()
    purge_invalid_amounts()
项目:sentinel    作者:dashpay    | 项目源码 | 文件源码
def check_db_schema_version():
    """ Ensure DB schema is correct version. Drop tables if not. """
    db_schema_version = None

    try:
        db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
    except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
        printdbg("[info]: Can't get DB_SCHEMA_VERSION...")

    printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
    printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
    if (SCHEMA_VERSION != db_schema_version):
        printdbg("[info]: Schema version mis-match. Syncing tables.")
        try:
            existing_table_names = db.get_tables()
            existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
            if (existing_models):
                printdbg("[info]: Dropping tables...")
                db.drop_tables(existing_models, safe=False, cascade=False)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            print("[error] Could not drop tables: %s" % e)
项目:aiowing    作者:embali    | 项目源码 | 文件源码
def get(self):
        page = int(self.request.match_info.get('page', 1))

        try:
            records = await settings.manager.execute(
                Record
                .select()
                .where(Record.active == True)
                .order_by(Record.name.asc())
                .offset((page - 1) * settings.RECORDS_PER_PAGE)
                .limit(settings.RECORDS_PER_PAGE + 1))
        except (psycopg2.OperationalError, peewee.IntegrityError,
                peewee.ProgrammingError):
            records = []

        count = len(records)

        if count == 0 and page != 1:
            return web.HTTPFound(self.request.app.router['web_records'].url())

        next_page = page + 1 if count > settings.RECORDS_PER_PAGE else None
        prev_page = page - 1 if page != 1 else None

        return dict(request=self.request,
                    records=records[:settings.RECORDS_PER_PAGE],
                    prev_page=prev_page,
                    page=page,
                    next_page=next_page)
项目:aiowing    作者:embali    | 项目源码 | 文件源码
def get_page_context(self, page):
        try:
            count = await settings.manager.count(Record.select())
        except (psycopg2.OperationalError, peewee.IntegrityError,
                peewee.ProgrammingError):
            count = 0

        page_count, prev_page, page, next_page = \
            await self.paging(count, settings.RECORDS_PER_PAGE, page)

        try:
            records = await settings.manager.execute(
                Record
                .select()
                .order_by(
                    Record.active.desc(),
                    Record.uts.desc())
                .paginate(page, paginate_by=settings.RECORDS_PER_PAGE))
        except (psycopg2.OperationalError, peewee.IntegrityError,
                peewee.ProgrammingError):
            records = []

        return {'request': self.request,
                'current_user': (await self.get_current_user()),
                'records': records,
                'count': count,
                'page_count': page_count,
                'prev_page': prev_page,
                'page': page,
                'next_page': next_page}
项目:tcrudge    作者:CodeTeam    | 项目源码 | 文件源码
def head(self):
        """
        Handles HEAD request.

        1. Validates GET parameters using GET input schema and validator.
        2. Fetches total amount of items and returns it in X-Total header.
        3. Finishes response.

        :raises: In case of bad query parameters - HTTPError 400.
        """
        await self.validate({k: self.get_argument(k) for k in self.request.query_arguments.keys()},
                            self.get_schema_input)
        try:
            qs = self.get_queryset(paginate=False)
        except AttributeError as e:
            # Wrong field name in filter or order_by
            # Request.body is not available in HEAD request
            # No detail info will be provided
            raise HTTPError(400)
        try:
            total_num = await self.application.objects.count(qs)
        except (peewee.DataError, peewee.ProgrammingError, ValueError) as e:
            # Bad parameters
            # Request.body is not available in HEAD request
            # No detail info will be provided
            raise HTTPError(400)
        self.set_header('X-Total', total_num)
        self.finish()
项目:sentinel-old    作者:monacocoin-net    | 项目源码 | 文件源码
def sync(self, monacoCoind):
        golist = monacoCoind.rpc_command('gobject', 'list')

        # objects which are removed from the network should be removed from the DB
        try:
            for purged in self.purged_network_objects(list(golist.keys())):
                # SOMEDAY: possible archive step here
                purged.delete_instance(recursive=True, delete_nullable=True)

            for item in golist.values():
                (go, subobj) = self.import_gobject_from_monacoCoind(monacoCoind, item)
        except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
            printdbg("Got an error upon import: %s" % e)
项目:peewee-db-evolve    作者:keredson    | 项目源码 | 文件源码
def test_drop_table(self):
    class SomeModel(pw.Model):
      some_field = pw.CharField(null=True)
      class Meta:
        database = self.db
    self.evolve_and_check_noop()
    SomeModel.create(some_field='woot')
    peeweedbevolve.clear()
    self.evolve_and_check_noop()
    with self.assertRaises(pw.ProgrammingError):
      SomeModel.create(some_field='woot2') # fails because table isn't there
项目:peewee-db-evolve    作者:keredson    | 项目源码 | 文件源码
def test_ignore_new_model(self):
    class SomeModel(pw.Model):
      some_field = pw.CharField(null=True)
      class Meta:
        database = self.db
        evolve = False
    self.evolve_and_check_noop()
    with self.assertRaises(pw.ProgrammingError):
      # should fail because table does not exist
      SomeModel.create(some_field='woot')