Skip to content

Commit

Permalink
Remove user model references
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Feb 24, 2025
1 parent aa78bbd commit 0c0c6df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions dash/orgs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django import forms
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.utils.translation import gettext_lazy as _

from .models import Org
Expand All @@ -17,7 +17,7 @@ class CreateOrgLoginForm(forms.Form):
def clean_email(self):
email = self.cleaned_data["email"]
if email:
if User.objects.filter(username__iexact=email):
if get_user_model().objects.filter(username__iexact=email):
raise forms.ValidationError(_("That email address is already used"))
return email.lower()

Expand All @@ -36,7 +36,7 @@ class OrgForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(OrgForm, self).__init__(*args, **kwargs)
if "administrators" in self.fields:
administrators = User.objects.exclude(username__in=["root", "root2"])
administrators = get_user_model().objects.exclude(username__in=["root", "root2"])
administrators = administrators.exclude(pk__lt=0)
self.fields["administrators"].queryset = administrators.order_by("username")

Expand Down
5 changes: 2 additions & 3 deletions dash/orgs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
from django import forms
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, get_user_model, login
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.http import HttpResponseRedirect
Expand Down Expand Up @@ -464,7 +463,7 @@ def post_save(self, obj):
if matcher:
user_type = matcher.group(1)
user_id = matcher.group(2)
user = User.objects.get(pk=user_id)
user = get_user_model().objects.get(pk=user_id)
if user_type == "administrators":
self.get_object().administrators.add(user)
if user_type == "editors":
Expand Down
6 changes: 4 additions & 2 deletions dash/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
from requests.structures import CaseInsensitiveDict

from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.http import JsonResponse
from django.test import TestCase

Expand Down Expand Up @@ -50,7 +50,9 @@ class DashTest(TestCase):
def setUp(self):
super(DashTest, self).setUp()

self.superuser = User.objects.create_superuser(username="testroot", email="super@user.com", password="root")
self.superuser = get_user_model().objects.create_superuser(
username="testroot", email="super@user.com", password="root"
)

self.clear_cache()

Expand Down

0 comments on commit 0c0c6df

Please sign in to comment.