当前位置: 首页>>代码示例>>Python>>正文


Python apps.apps方法代码示例

本文整理汇总了Python中django.apps.apps方法的典型用法代码示例。如果您正苦于以下问题:Python apps.apps方法的具体用法?Python apps.apps怎么用?Python apps.apps使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.apps的用法示例。


在下文中一共展示了apps.apps方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_permissions

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def update_permissions(sender, app_config, verbosity, apps=global_apps,
                       **kwargs):
    settings_models = getattr(settings, 'ADMIN_VIEW_PERMISSION_MODELS', None)

    # TODO: Maybe look at the registry not in all models
    for app in apps.get_app_configs():
        for model in app.get_models():
            view_permission = 'view_%s' % model._meta.model_name
            if settings_models or (settings_models is not None and len(
                    settings_models) == 0):
                model_name = get_model_name(model)
                if model_name in settings_models and view_permission not in \
                        [perm[0] for perm in model._meta.permissions]:
                    model._meta.permissions += (
                        (view_permission,
                         'Can view %s' % model._meta.model_name),)
            else:
                if view_permission not in [perm[0] for perm in
                                           model._meta.permissions]:
                    model._meta.permissions += (
                        ('view_%s' % model._meta.model_name,
                         'Can view %s' % model._meta.model_name),) 
开发者ID:ctxis,项目名称:django-admin-view-permission,代码行数:24,代码来源:apps.py

示例2: handle

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def handle(self, *args, **options):
        changed = set()

        self.stdout.write("Checking...")
        for db in settings.DATABASES.keys():
            try:
                executor = MigrationExecutor(connections[db])
            except OperationalError:
                sys.exit("Unable to check migrations: cannot connect to database\n")

            autodetector = MigrationAutodetector(
                executor.loader.project_state(), ProjectState.from_apps(apps),
            )
            changed.update(autodetector.changes(graph=executor.loader.graph).keys())

        changed -= set(options["ignore"])

        if changed:
            sys.exit(
                "Apps with model changes but no corresponding migration file: %(changed)s\n"
                % {"changed": list(changed)}
            )
        else:
            sys.stdout.write("All migration files present\n") 
开发者ID:vintasoftware,项目名称:django-react-boilerplate,代码行数:26,代码来源:has_missing_migrations.py

示例3: test_migration_11

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_migration_11(self):
        # create users with the CI feature off
        # to replicate pre feature database state
        with override_settings(ST_CASE_INSENSITIVE_USERNAMES=False):
            utils.create_user(username='FOO')
            utils.create_user(username='BaR')
            utils.create_user(username='baz')
        # default all nicknames to empty
        self.assertEqual(
            UserProfile.objects.all().update(nickname=''), 3)
        data_migration_11.populate_nickname(apps, None)
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO', 'BaR', 'baz'])

        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['FOO', 'BaR', 'baz'])
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['foo', 'bar', 'baz'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO', 'BaR', 'baz']) 
开发者ID:nitely,项目名称:Spirit,代码行数:27,代码来源:tests.py

示例4: test_migration_11_no_ci_usernames

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_migration_11_no_ci_usernames(self):
        utils.create_user(username='FOO')
        utils.create_user(username='foo')
        utils.create_user(username='BaR')
        utils.create_user(username='bar')
        utils.create_user(username='baz')

        self.assertEqual(
            UserProfile.objects.all().update(nickname=''), 5)
        data_migration_11.populate_nickname(apps, None)
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO', 'foo', 'BaR', 'bar', 'baz'])

        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['FOO', 'foo', 'BaR', 'bar', 'baz'])
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['FOO', 'foo', 'BaR', 'bar', 'baz'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO', 'foo', 'BaR', 'bar', 'baz']) 
开发者ID:nitely,项目名称:Spirit,代码行数:26,代码来源:tests.py

示例5: test_migration_11_make_usernames_lower_integrity_err

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_migration_11_make_usernames_lower_integrity_err(self):
        with override_settings(ST_CASE_INSENSITIVE_USERNAMES=False):
            utils.create_user(username='FOO')
            utils.create_user(username='fOo')
            utils.create_user(username='Foo')
            utils.create_user(username='bar')
            utils.create_user(username='bAr')
            utils.create_user(username='baz')

        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['FOO', 'fOo', 'Foo', 'bar', 'bAr', 'baz'])

        # transaction is already handled
        with self.assertRaises(IntegrityError) as cm:
            data_migration_11.make_usernames_lower(apps, None)
            self.maxDiff = None
            self.assertEqual(
                str(cm.exception),
                "There are two or more users with similar name but "
                "different casing, for example: someUser and SomeUser, "
                "either remove one of them or set the "
                "`ST_CASE_INSENSITIVE_USERNAMES` setting to False. "
                "Then run the upgrade/migration again. Any change was reverted. "
                "Duplicate users are ['FOO', 'fOo', 'Foo', 'bar', 'bAr']") 
开发者ID:nitely,项目名称:Spirit,代码行数:27,代码来源:tests.py

示例6: test_migration_11_idempotency

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_migration_11_idempotency(self):
        """Should be idempotent"""
        with override_settings(ST_CASE_INSENSITIVE_USERNAMES=False):
            utils.create_user(username='FOO')
        self.assertEqual(
            UserProfile.objects.all().update(nickname=''), 1)
        data_migration_11.populate_nickname(apps, None)
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['foo'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO'])
        data_migration_11.populate_nickname(apps, None)
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['foo'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO']) 
开发者ID:nitely,项目名称:Spirit,代码行数:24,代码来源:tests.py

示例7: test_abstract_model_pending_operations

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_abstract_model_pending_operations(self):
        """
        Many-to-many fields declared on abstract models should not add lazy
        relations to resolve relationship declared as string (#24215).
        """
        pending_ops_before = list(apps._pending_operations.items())

        class AbstractManyToManyModel(models.Model):
            fk = models.ForeignKey('missing.FK', models.CASCADE)

            class Meta:
                abstract = True

        self.assertIs(AbstractManyToManyModel._meta.apps, apps)
        self.assertEqual(
            pending_ops_before,
            list(apps._pending_operations.items()),
            'Pending lookup added for a many-to-many field on an abstract model'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_manytomanyfield.py

示例8: test_abstract_model_pending_operations

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_abstract_model_pending_operations(self):
        """
        Foreign key fields declared on abstract models should not add lazy
        relations to resolve relationship declared as string (#24215).
        """
        pending_ops_before = list(apps._pending_operations.items())

        class AbstractForeignKeyModel(models.Model):
            fk = models.ForeignKey('missing.FK', models.CASCADE)

            class Meta:
                abstract = True

        self.assertIs(AbstractForeignKeyModel._meta.apps, apps)
        self.assertEqual(
            pending_ops_before,
            list(apps._pending_operations.items()),
            'Pending lookup added for a foreign key on an abstract model'
        ) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_foreignkey.py

示例9: add_field

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def add_field(field, filters: List[str]):
    """Adds the specified field to a model.

    Arguments:
        field:
            The field to add to a model.

        filters:
            List of strings to filter
            SQL statements on.
    """

    model = define_fake_model()
    state = migrations.state.ProjectState.from_apps(apps)

    apply_migration([migrations.CreateModel(model.__name__, fields=[])], state)

    with filtered_schema_editor(*filters) as calls:
        apply_migration(
            [migrations.AddField(model.__name__, "title", field)], state
        )

    yield calls 
开发者ID:SectorLabs,项目名称:django-postgres-extra,代码行数:25,代码来源:migrations.py

示例10: run

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def run(self, *args, **kwargs):

        changed = set()

        log.info("Checking DB migrations")
        for db in settings.DATABASES.keys():

            try:
                executor = MigrationExecutor(connections[db])
            except OperationalError:
                log.critical("Unable to check migrations, cannot connect to database")
                sys.exit(1)

            autodetector = MigrationAutodetector(
                executor.loader.project_state(), ProjectState.from_apps(apps)
            )

            changed.update(autodetector.changes(graph=executor.loader.graph).keys())

        if changed:
            log.critical(
                "Apps with model changes but no corresponding "
                f"migration file: {list(changed)}"
            )
            sys.exit(1)
        else:
            log.info("All migration files present") 
开发者ID:webkom,项目名称:lego,代码行数:29,代码来源:missing_migrations.py

示例11: add_arguments

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def add_arguments(self, parser):
        parser.add_argument(
            "--ignore",
            action="store",
            nargs="+",
            dest="ignore",
            default=[],
            help="Comma separated list of apps to ignore missing migration files. "
            "Useful for specifying third-party ones here.",
        ) 
开发者ID:vintasoftware,项目名称:django-react-boilerplate,代码行数:12,代码来源:has_missing_migrations.py

示例12: test_for_missing_migrations

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_for_missing_migrations(self):
        """Checks if there're models changes which aren't reflected in migrations."""
        migrations_loader = MigrationExecutor(connection).loader
        migrations_detector = MigrationAutodetector(
            from_state=migrations_loader.project_state(),
            to_state=ProjectState.from_apps(apps)
        )
        if migrations_detector.changes(graph=migrations_loader.graph):
            self.fail(
                'Your models have changes that are not yet reflected '
                'in a migration. You should add them now.'
            ) 
开发者ID:yunojuno-archive,项目名称:django-package-monitor,代码行数:14,代码来源:test_migrations.py

示例13: test_for_missing_migrations

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_for_missing_migrations(self):
        """Checks if there're models changes which aren't reflected in migrations."""
        migrations_loader = MigrationExecutor(connection).loader
        migrations_detector = MigrationAutodetector(
            from_state=migrations_loader.project_state(),
            to_state=ProjectState.from_apps(apps),
        )
        if migrations_detector.changes(graph=migrations_loader.graph):
            self.fail(
                "Your models have changes that are not yet reflected "
                "in a migration. You should add them now."
            ) 
开发者ID:yunojuno,项目名称:django-request-profiler,代码行数:14,代码来源:test_middleware.py

示例14: handle

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def handle(self, *args, **kwargs):

        changed = set()
        ignore_list = ['authtools']  # dependencies that we don't care about migrations for (usually for testing only)

        self.stdout.write("Checking...")
        for db in settings.DATABASES.keys():

            try:
                executor = MigrationExecutor(connections[db])
            except OperationalError:
                sys.exit("Unable to check migrations: cannot connect to database\n")

            autodetector = MigrationAutodetector(
                executor.loader.project_state(),
                ProjectState.from_apps(apps),
            )

            changed.update(autodetector.changes(graph=executor.loader.graph).keys())

        for ignore in ignore_list:
            if ignore in changed:
                changed.remove(ignore)

        if changed:
            sys.exit("Apps with model changes but no corresponding migration file: %(changed)s\n" % {
                'changed': list(changed)
            })
        else:
            sys.stdout.write("All migration files present\n") 
开发者ID:WimpyAnalytics,项目名称:django-andablog,代码行数:32,代码来源:check_missing_migrations.py

示例15: test_migration_profiles

# 需要导入模块: from django import apps [as 别名]
# 或者: from django.apps import apps [as 别名]
def test_migration_profiles(self):
        """Should create profile for existing users"""
        foo = utils.create_user(username='foo')
        bar = utils.create_user(username='bar')
        UserProfile.objects.filter(user=foo).delete()
        UserProfile.objects.filter(user=bar).delete()
        foo = User.objects.get(pk=foo.pk)
        bar = User.objects.get(pk=bar.pk)
        with self.assertRaises(ObjectDoesNotExist):
            self.assertIsNone(foo.st)
        with self.assertRaises(ObjectDoesNotExist):
            self.assertIsNone(bar.st)
        data_migration_profiles.migrate_profiles(apps, None)
        self.assertTrue(User.objects.get(pk=foo.pk).st.is_verified)
        self.assertTrue(User.objects.get(pk=bar.pk).st.is_verified) 
开发者ID:nitely,项目名称:Spirit,代码行数:17,代码来源:tests.py


注:本文中的django.apps.apps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。