Skip to content

Commit 74f673f

Browse files
committed
Get Auth User Model use the right way.
1 parent c01a258 commit 74f673f

4 files changed

Lines changed: 5 additions & 15 deletions

File tree

xadmin/forms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from django.utils.translation import ugettext_lazy, ugettext as _
77

8-
from xadmin.util import User
8+
from django.contrib.auth import get_user_model
99

1010
ERROR_MESSAGE = ugettext_lazy("Please enter the correct username and password "
1111
"for a staff account. Note that both fields are case-sensitive.")
@@ -30,6 +30,7 @@ def clean(self):
3030
username=username, password=password)
3131
if self.user_cache is None:
3232
if u'@' in username:
33+
User = get_user_model()
3334
# Mistakenly entered e-mail address instead of username? Look it up.
3435
try:
3536
user = User.objects.get(email=username)

xadmin/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
import decimal
1818
from xadmin.util import quote
1919

20-
if 4 < django.VERSION[1] < 7:
21-
AUTH_USER_MODEL = django.contrib.auth.get_user_model()
22-
else:
23-
AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
24-
20+
AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
2521

2622
def add_view_permissions(sender, **kwargs):
2723
"""

xadmin/plugins/auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
from django.utils.translation import ugettext as _
1212
from django.views.decorators.debug import sensitive_post_parameters
1313
from django.forms import ModelMultipleChoiceField
14+
from django.contrib.auth.models import User
1415
from xadmin.layout import Fieldset, Main, Side, Row, FormHelper
1516
from xadmin.sites import site
16-
from xadmin.util import unquote, User
17+
from xadmin.util import unquote
1718
from xadmin.views import BaseAdminPlugin, ModelFormAdminView, ModelAdminView, CommAdminView, csrf_protect_m
1819

1920

xadmin/util.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@
3333
except ImportError:
3434
from django.utils.timezone import localtime as tz_localtime
3535

36-
try:
37-
from django.contrib.auth import get_user_model
38-
User = get_user_model()
39-
username_field = User.USERNAME_FIELD
40-
except Exception:
41-
from django.contrib.auth.models import User
42-
username_field = 'username'
43-
4436

4537
def xstatic(*tags):
4638
from vendors import vendors

0 commit comments

Comments
 (0)