Python django.conf.settings.AUTH_USER_MODEL Examples
The following are 30 code examples for showing how to use django.conf.settings.AUTH_USER_MODEL(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example 1
Project: django-river Author: javrasya File: config.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def settings(self): if self.cached_settings: return self.cached_settings else: from django.conf import settings allowed_configurations = { 'CONTENT_TYPE_CLASS': ContentType, 'USER_CLASS': settings.AUTH_USER_MODEL, 'PERMISSION_CLASS': Permission, 'GROUP_CLASS': Group, 'INJECT_MODEL_ADMIN': False } river_settings = {} for key, default in allowed_configurations.items(): river_settings[key] = getattr(settings, self.get_with_prefix(key), default) river_settings['IS_MSSQL'] = connection.vendor == 'microsoft' self.cached_settings = river_settings return self.cached_settings
Example 2
Project: django-hijack-admin Author: arteria File: test_checks.py License: MIT License | 6 votes |
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())
Example 3
Project: codesy Author: codesy File: __init__.py License: GNU Affero General Public License v3.0 | 6 votes |
def setUp(self): """ Set up the following claim senarios user1: asks 50 user2: offers 25 user3: offers 25 user1 claims """ self.url = 'http://github.com/codesy/codesy/issues/37' self.issue = mommy.make(Issue, url=self.url) self.user1 = mommy.make(settings.AUTH_USER_MODEL, email='user1@test.com') self.user2 = mommy.make(settings.AUTH_USER_MODEL, email='user2@test.com') self.user3 = mommy.make(settings.AUTH_USER_MODEL, email='user3@test.com') self.bid1 = mommy.make(Bid, user=self.user1, ask=50, offer=0, url=self.url, issue=self.issue) self.bid2 = mommy.make(Bid, user=self.user2, ask=0, offer=25, url=self.url, issue=self.issue) self.bid3 = mommy.make(Bid, user=self.user3, ask=0, offer=25, url=self.url, issue=self.issue) self.claim = mommy.make(Claim, user=self.user1, issue=self.issue)
Example 4
Project: codesy Author: codesy File: model_tests.py License: GNU Affero General Public License v3.0 | 6 votes |
def test_send_mail_to_matching_askers(self, mock_send_mail): user = mommy.make(settings.AUTH_USER_MODEL) bid1_subject = "[codesy] There's $50 waiting for you!" bid2_subject = "[codesy] There's $100 waiting for you!" mock_send_mail.expects_call().with_args( bid1_subject, arg.any(), arg.any(), ['user1@test.com'] ) mock_send_mail.next_call().with_args( bid2_subject, arg.any(), arg.any(), ['user2@test.com'] ) offer_bid = mommy.make( Bid, offer=100, user=user, ask=1000, url=self.url ) offer_bid.save()
Example 5
Project: codesy Author: codesy File: model_tests.py License: GNU Affero General Public License v3.0 | 6 votes |
def test_only_send_mail_to_unsent_matching_askers(self, mock_send_mail): user = mommy.make(settings.AUTH_USER_MODEL) self.bid1.ask_match_sent = timezone.now() self.bid1.save() subject = "[codesy] There's $100 waiting for you!" mock_send_mail.expects_call().with_args( subject, arg.any(), arg.any(), ['user2@test.com'] ) offer_bid = mommy.make( Bid, offer=100, user=user, ask=1000, url=self.url ) offer_bid.save()
Example 6
Project: codesy Author: codesy File: model_tests.py License: GNU Affero General Public License v3.0 | 6 votes |
def setUp(self): """ Add a final bid and a user2 claim to the MarketWithBidsTestCase, so the final market for the bug is now: url: http://github.com/codesy/codesy/issues/37 user1: ask 50, offer 0 (ask is met) user2: ask 100, offer 10 user3: ask 0, offer 30 user4: ask 200, offer 10 And user1 is making the claim """ super(NotifyMatchingOfferersTest, self).setUp() self.user4 = mommy.make(settings.AUTH_USER_MODEL, email='user4@test.com') self.bid4 = mommy.make(Bid, user=self.user4, ask=200, offer=10, url=self.url) self.evidence = ('https://github.com/codesy/codesy/commit/' '4f1bcd014ec735918bebd1c386e2f99a7f83ff64')
Example 7
Project: codesy Author: codesy File: view_tests.py License: GNU Affero General Public License v3.0 | 6 votes |
def setUp(self): self.view = ClaimStatusView() self.url = 'http://github.com/codesy/codesy/issues/37' self.issue = mommy.make(Issue, url=self.url) self.user1 = mommy.make( settings.AUTH_USER_MODEL, email='user1@test.com' ) self.bid1 = mommy.make( Bid, user=self.user1, url=self.url, issue=self.issue, offer=0 ) self.user2 = mommy.make( settings.AUTH_USER_MODEL, email='user2@test.com' ) self.bid2 = mommy.make( Bid, user=self.user2, url=self.url, issue=self.issue, offer=10 ) self.user3 = mommy.make( settings.AUTH_USER_MODEL, email='user3@test.com' ) self.claim = mommy.make(Claim, user=self.user1, issue=self.issue)
Example 8
Project: django-request-profiler Author: yunojuno File: models.py License: MIT License | 6 votes |
def match_user(self, user: AUTH_USER_MODEL) -> bool: """Return True if the user passes the various user filters.""" # treat no user (i.e. has not been added) as AnonymousUser() user = user or AnonymousUser() if self.user_filter_type == RuleSet.USER_FILTER_ALL: return True if self.user_filter_type == RuleSet.USER_FILTER_AUTH: return user.is_authenticated if self.user_filter_type == RuleSet.USER_FILTER_GROUP: group = self.user_group_filter.strip() return user.groups.filter(name__iexact=group).exists() # if we're still going, then it's a no. it's also an invalid # user_filter_type, so we may want to think about a warning return False
Example 9
Project: openhgsenti Author: drexly File: state.py License: Apache License 2.0 | 6 votes |
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))
Example 10
Project: openwisp-users Author: openwisp File: apps.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_default_menu_items(self): menu_setting = 'OPENWISP_DEFAULT_ADMIN_MENU_ITEMS' items = [ {'model': settings.AUTH_USER_MODEL}, {'model': get_model_name('openwisp_users', 'Organization')}, ] if not hasattr(settings, menu_setting): setattr(settings, menu_setting, items) else: current_menu = getattr(settings, menu_setting) current_menu += items
Example 11
Project: django-hijack-admin Author: arteria File: checks.py License: MIT License | 5 votes |
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
Example 12
Project: GTDWeb Author: lanbing510 File: state.py License: GNU General Public License v2.0 | 5 votes |
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) # If there are some lookups left, see if we can first resolve them # ourselves - sometimes fields are added after class_prepared is sent for lookup_model, operations in self._pending_lookups.items(): try: model = self.get_model(lookup_model[0], lookup_model[1]) except LookupError: app_label = "%s.%s" % (lookup_model[0], lookup_model[1]) if app_label == settings.AUTH_USER_MODEL and ignore_swappable: continue # Raise an error with a best-effort helpful message # (only for the first issue). Error message should look like: # "ValueError: Lookup failed for model referenced by # field migrations.Book.author: migrations.Author" msg = "Lookup failed for model referenced by field {field}: {model[0]}.{model[1]}" raise ValueError(msg.format(field=operations[0][1], model=lookup_model)) else: do_pending_lookups(model)
Example 13
Project: GTDWeb Author: lanbing510 File: __init__.py License: GNU General Public License v2.0 | 5 votes |
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 )
Example 14
Project: GTDWeb Author: lanbing510 File: utils.py License: GNU General Public License v2.0 | 5 votes |
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)
Example 15
Project: readux Author: ecds File: conftest.py License: MIT License | 5 votes |
def user() -> settings.AUTH_USER_MODEL: return UserFactory()
Example 16
Project: readux Author: ecds File: test_views.py License: MIT License | 5 votes |
def test_get_success_url( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request # assert view.get_success_url() == f"/users/{user.username}/"
Example 17
Project: readux Author: ecds File: test_views.py License: MIT License | 5 votes |
def test_get_object( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request assert view.get_object() == user
Example 18
Project: readux Author: ecds File: test_views.py License: MIT License | 5 votes |
def test_get_redirect_url( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserRedirectView() request = request_factory.get("/fake-url") request.user = user view.request = request # assert view.get_redirect_url() == f"/users/{user.username}/"
Example 19
Project: django-useraudit Author: muccg File: tests.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example 20
Project: django-admin-view-permission Author: ctxis File: admin.py License: BSD 2-Clause "Simplified" License | 5 votes |
def register(self, model_or_iterable, admin_class=None, **options): """ Create a new ModelAdmin class which inherits from the original and the above and register all models with that """ SETTINGS_MODELS = getattr( settings, 'ADMIN_VIEW_PERMISSION_MODELS', None) models = model_or_iterable if not isinstance(model_or_iterable, (tuple, list)): models = tuple([model_or_iterable]) is_user_model = settings.AUTH_USER_MODEL in [ get_model_name(i) for i in models] if SETTINGS_MODELS or (SETTINGS_MODELS is not None and len( SETTINGS_MODELS) == 0): for model in models: model_name = get_model_name(model) if model_name in SETTINGS_MODELS: admin_class = self._get_admin_class( admin_class, is_user_model) super(AdminViewPermissionAdminSite, self).register( [model], admin_class, **options) else: admin_class = self._get_admin_class(admin_class, is_user_model) super(AdminViewPermissionAdminSite, self).register( model_or_iterable, admin_class, **options)
Example 21
Project: Pytition Author: pytition File: 0007_auto_20190807_2221.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def createPytitionUsers(apps, schema_editor): PytitionUser = apps.get_model('petition', 'PytitionUser') User = apps.get_model(*settings.AUTH_USER_MODEL.split('.')) for u in User.objects.all(): print("Creating PU for User \'{}\'".format(u.username)) if u.first_name == '' and u.last_name == '': u.first_name = u.username PytitionUser.objects.create(user=u) u.save()
Example 22
Project: bioforum Author: reBiocoder File: state.py License: MIT License | 5 votes |
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().__init__(app_configs) # The lock gets in the way of copying as implemented in clone(), which # is called whenever Django duplicates a StateApps before updating it. self._lock = None 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))
Example 23
Project: bioforum Author: reBiocoder File: __init__.py License: MIT License | 5 votes |
def get_user_model(): """ Return 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 )
Example 24
Project: django_cookiecutter_docker Author: realpython File: conftest.py License: MIT License | 5 votes |
def user() -> settings.AUTH_USER_MODEL: return UserFactory()
Example 25
Project: django_cookiecutter_docker Author: realpython File: test_views.py License: MIT License | 5 votes |
def test_get_success_url( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request assert view.get_success_url() == f"/users/{user.username}/"
Example 26
Project: django_cookiecutter_docker Author: realpython File: test_views.py License: MIT License | 5 votes |
def test_get_object( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserUpdateView() request = request_factory.get("/fake-url/") request.user = user view.request = request assert view.get_object() == user
Example 27
Project: django_cookiecutter_docker Author: realpython File: test_views.py License: MIT License | 5 votes |
def test_get_redirect_url( self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory ): view = UserRedirectView() request = request_factory.get("/fake-url") request.user = user view.request = request assert view.get_redirect_url() == f"/users/{user.username}/"
Example 28
Project: django_cookiecutter_docker Author: realpython File: test_urls.py License: MIT License | 5 votes |
def test_detail(user: settings.AUTH_USER_MODEL): assert ( reverse("users:detail", kwargs={"username": user.username}) == f"/users/{user.username}/" ) assert resolve(f"/users/{user.username}/").view_name == "users:detail"
Example 29
Project: django-webdav-storage Author: marazmiki File: 0002_auto_20171228_2210.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def drop_superuser(apps, schema_editor): apps.get_model(settings.AUTH_USER_MODEL).objects.filter( username='admin', email='admin@example.com', ).delete()
Example 30
Project: codesy Author: codesy File: view_tests.py License: GNU Affero General Public License v3.0 | 5 votes |
def test_get_object(self): user = mommy.make(settings.AUTH_USER_MODEL) self.view.request = fudge.Fake().has_attr(user=user) obj = self.view.get_object() self.assertEqual(obj, user)