python类AUTH_USER_MODEL的实例源码

utils.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
state.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def __init__(self, real_apps, models, ignore_swappable=False):
        # Any apps in self.real_apps should have all their models included
        # in the render. We don't use the original model instances as there
        # are some variables that refer to the Apps object.
        # FKs/M2Ms from real apps are also not included as they just
        # mess things up with partial states (due to lack of dependencies)
        self.real_models = []
        for app_label in real_apps:
            app = global_apps.get_app_config(app_label)
            for model in app.get_models():
                self.real_models.append(ModelState.from_model(model, exclude_rels=True))
        # Populate the app registry with a stub for each application.
        app_labels = {model_state.app_label for model_state in models.values()}
        app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
        super(StateApps, self).__init__(app_configs)

        self.render_multiple(list(models.values()) + self.real_models)

        # There shouldn't be any operations pending at this point.
        from django.core.checks.model_checks import _check_lazy_references
        ignore = {make_model_tuple(settings.AUTH_USER_MODEL)} if ignore_swappable else set()
        errors = _check_lazy_references(self, ignore=ignore)
        if errors:
            raise ValueError("\n".join(error.msg for error in errors))
0010_migrate_use_structure.py 文件源码 项目:DjangoCMS 作者: farhan711 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def forwards(apps, schema_editor):
    user_model = apps.get_model(settings.AUTH_USER_MODEL)
    ph_model = apps.get_model('cms', 'Placeholder')
    page_model = apps.get_model('cms', 'Page')
    try:
        ph_ctype = ContentType.objects.get_for_model(ph_model)
        page_ctype = ContentType.objects.get_for_model(page_model)
        permission, __ = Permission.objects.get_or_create(
            codename='use_structure', content_type=ph_ctype, name=u"Can use Structure mode")
        page_permission, __ = Permission.objects.get_or_create(codename='change_page', content_type=page_ctype)
        for user in user_model.objects.filter(is_superuser=False, is_staff=True):
            if user.user_permissions.filter(codename='change_page', content_type_id=page_ctype.pk).exists():
                user.user_permissions.add(permission.pk)
        for group in Group.objects.all():
            if page_permission in group.permissions.all():
                group.permissions.add(permission.pk)
    except Exception:
        warnings.warn(u'Users not migrated to use_structure permission, please add the permission manually')
state.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __init__(self, real_apps, models, ignore_swappable=False):
        # Any apps in self.real_apps should have all their models included
        # in the render. We don't use the original model instances as there
        # are some variables that refer to the Apps object.
        # FKs/M2Ms from real apps are also not included as they just
        # mess things up with partial states (due to lack of dependencies)
        self.real_models = []
        for app_label in real_apps:
            app = global_apps.get_app_config(app_label)
            for model in app.get_models():
                self.real_models.append(ModelState.from_model(model, exclude_rels=True))
        # Populate the app registry with a stub for each application.
        app_labels = {model_state.app_label for model_state in models.values()}
        app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
        super(StateApps, self).__init__(app_configs)

        self.render_multiple(list(models.values()) + self.real_models)

        # There shouldn't be any operations pending at this point.
        pending_models = set(self._pending_operations)
        if ignore_swappable:
            pending_models -= {make_model_tuple(settings.AUTH_USER_MODEL)}
        if pending_models:
            raise ValueError(self._pending_models_error(pending_models))
state.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, real_apps, models, ignore_swappable=False):
        # Any apps in self.real_apps should have all their models included
        # in the render. We don't use the original model instances as there
        # are some variables that refer to the Apps object.
        # FKs/M2Ms from real apps are also not included as they just
        # mess things up with partial states (due to lack of dependencies)
        self.real_models = []
        for app_label in real_apps:
            app = global_apps.get_app_config(app_label)
            for model in app.get_models():
                self.real_models.append(ModelState.from_model(model, exclude_rels=True))
        # Populate the app registry with a stub for each application.
        app_labels = {model_state.app_label for model_state in models.values()}
        app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
        super(StateApps, self).__init__(app_configs)

        self.render_multiple(list(models.values()) + self.real_models)

        # There shouldn't be any operations pending at this point.
        pending_models = set(self._pending_operations)
        if ignore_swappable:
            pending_models -= {make_model_tuple(settings.AUTH_USER_MODEL)}
        if pending_models:
            raise ValueError(self._pending_models_error(pending_models))
utils.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
state.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, real_apps, models, ignore_swappable=False):
        # Any apps in self.real_apps should have all their models included
        # in the render. We don't use the original model instances as there
        # are some variables that refer to the Apps object.
        # FKs/M2Ms from real apps are also not included as they just
        # mess things up with partial states (due to lack of dependencies)
        self.real_models = []
        for app_label in real_apps:
            app = global_apps.get_app_config(app_label)
            for model in app.get_models():
                self.real_models.append(ModelState.from_model(model, exclude_rels=True))
        # Populate the app registry with a stub for each application.
        app_labels = {model_state.app_label for model_state in models.values()}
        app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
        super(StateApps, self).__init__(app_configs)

        self.render_multiple(list(models.values()) + self.real_models)

        # There shouldn't be any operations pending at this point.
        pending_models = set(self._pending_operations)
        if ignore_swappable:
            pending_models -= {make_model_tuple(settings.AUTH_USER_MODEL)}
        if pending_models:
            raise ValueError(self._pending_models_error(pending_models))
utils.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
utils.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
test_checks.py 文件源码 项目:django-hijack-admin 作者: arteria 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_check_custom_user_model_default_admin(self):
            # Django doesn't re-register admins when using `override_settings`,
            # so we have to do it manually in this test case.
            admin.site.register(get_user_model(), UserAdmin)

            warnings = checks.check_custom_user_model(HijackAdminConfig)
            expected_warnings = [
                Warning(
                    'django-hijack-admin does not work out the box with a custom user model.',
                    hint='Please mix HijackUserAdminMixin into your custom UserAdmin.',
                    obj=settings.AUTH_USER_MODEL,
                    id='hijack_admin.W001',
                )
            ]
            self.assertEqual(warnings, expected_warnings)

            admin.site.unregister(get_user_model())
checks.py 文件源码 项目:django-hijack-admin 作者: arteria 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def check_custom_user_model(app_configs, **kwargs):
    warnings = []
    if (settings.AUTH_USER_MODEL != DEFAULT_AUTH_USER_MODEL and
            not _using_hijack_admin_mixin()):
        warnings.append(
            Warning(
                'django-hijack-admin does not work out the box with a custom user model.',
                hint='Please mix HijackUserAdminMixin into your custom UserAdmin.',
                obj=settings.AUTH_USER_MODEL,
                id='hijack_admin.W001',
            )
        )
    return warnings
conftest.py 文件源码 项目:django-redis-pubsub 作者: andrewyoung1991 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def subscriber(request):
    subscriber_ = mommy.make(settings.AUTH_USER_MODEL)
    def fin():
        subscriber_.delete()
    request.addfinalizer(fin)
    return subscriber_
0001_initial.py 文件源码 项目:PonyConf 作者: PonyConf 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def profile_forward(apps, schema_editor):
    User = apps.get_model(settings.AUTH_USER_MODEL)
    Profile = apps.get_model("accounts", "Profile")
    db_alias = schema_editor.connection.alias
    for user in User.objects.using(db_alias).all():
        Profile.objects.using(db_alias).get_or_create(user=user)
utils.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
tests.py 文件源码 项目:no-design-slack-clone 作者: metsavaht 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_custom_user_model():
    assert settings.AUTH_USER_MODEL == 'accounts.User'
utils.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
test_models.py 文件源码 项目:django-horizon 作者: uncovertruth 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_check_horizontal_meta_without_horitontal_group(self):
        class WithoutHorizontalGroupModel(AbstractHorizontalModel):
            user = models.ForeignKey(
                settings.AUTH_USER_MODEL,
                on_delete=models.DO_NOTHING,
                db_constraint=False,
            )

            class Meta(object):
                horizontal_key = 'user'
        errors = WithoutHorizontalGroupModel.check()
        self.assertEqual(1, len(errors))
        self.assertEqual('horizon.E001', errors[0].id)
test_models.py 文件源码 项目:django-horizon 作者: uncovertruth 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_check_horizontal_meta_without_horitontal_key(self):
        class WithoutHorizontalKeyModel(AbstractHorizontalModel):
            user = models.ForeignKey(
                settings.AUTH_USER_MODEL,
                on_delete=models.DO_NOTHING,
                db_constraint=False,
            )

            class Meta(object):
                horizontal_group = 'a'
        errors = WithoutHorizontalKeyModel.check()
        self.assertEqual(1, len(errors))
        self.assertEqual('horizon.E001', errors[0].id)
test_models.py 文件源码 项目:django-horizon 作者: uncovertruth 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_check_horizontal_meta_wrong_horizontal_group(self):
        class WrongGroupModel(AbstractHorizontalModel):
            user = models.ForeignKey(
                settings.AUTH_USER_MODEL,
                on_delete=models.DO_NOTHING,
                db_constraint=False,
            )

            class Meta(object):
                horizontal_group = 'wrong'
                horizontal_key = 'user'
        errors = WrongGroupModel.check()
        self.assertEqual(1, len(errors))
        self.assertEqual('horizon.E002', errors[0].id)
test_models.py 文件源码 项目:django-horizon 作者: uncovertruth 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_check_horizontal_meta_wrong_horizontal_key(self):
        class WrongKeyModel(AbstractHorizontalModel):
            user = models.ForeignKey(
                settings.AUTH_USER_MODEL,
                on_delete=models.DO_NOTHING,
                db_constraint=False,
            )

            class Meta(object):
                horizontal_group = 'a'
                horizontal_key = 'wrong'
        errors = WrongKeyModel.check()
        self.assertEqual(1, len(errors))
        self.assertEqual('horizon.E003', errors[0].id)
tests.py 文件源码 项目:django-useraudit 作者: muccg 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def register_pre_save_on_AUTH_USER_MODER_change(sender, setting, value, enter, **kwargs):
    if setting == "AUTH_USER_MODEL" and value != USER_MODEL:
        if enter:
            pre_save.connect(useraudit.password_expiry.user_pre_save, sender=value)
        else:
            pre_save.disconnect(useraudit.password_expiry.user_pre_save, sender=value)
utils.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)
__init__.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_user_model():
    """
    Returns the User model that is active in this project.
    """
    try:
        return django_apps.get_model(settings.AUTH_USER_MODEL)
    except ValueError:
        raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
    except LookupError:
        raise ImproperlyConfigured(
            "AUTH_USER_MODEL refers to model '%s' that has not been installed" % settings.AUTH_USER_MODEL
        )
utils.py 文件源码 项目:tabmaster 作者: NicolasMinghetti 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def skipIfCustomUser(test_func):
    """
    Skip a test if a custom user model is in use.
    """
    warnings.warn(
        "django.contrib.auth.tests.utils.skipIfCustomUser is deprecated.",
        RemovedInDjango20Warning, stacklevel=2)

    return skipIf(settings.AUTH_USER_MODEL != 'auth.User', 'Custom user model in use')(test_func)


问题


面经


文章

微信
公众号

扫码关注公众号