Skip to content
Browse files

Allowed reuse of auth.forms for custom User models

  • Loading branch information...
1 parent dfd7213 commit 04ae5183df8613fd0d91b43834a4582fdf6b0d04 @akaariai committed Sep 16, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 django/contrib/auth/forms.py
View
16 django/contrib/auth/forms.py
@@ -9,12 +9,12 @@
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext, ugettext_lazy as _
-from django.contrib.auth import authenticate
+from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth.models import User
from django.contrib.auth.hashers import UNUSABLE_PASSWORD, identify_hasher
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import get_current_site
-
+UserModel = get_user_model()
UNMASKED_DIGITS_TO_SHOW = 6
@@ -75,16 +75,16 @@ class UserCreationForm(forms.ModelForm):
help_text=_("Enter the same password as above, for verification."))
class Meta:
- model = User
+ model = UserModel
fields = ("username",)
def clean_username(self):
# Since User.username is unique, this check is redundant,
# but it sets a nicer error message than the ORM. See #13147.
username = self.cleaned_data["username"]
try:
- User.objects.get(username=username)
- except User.DoesNotExist:
+ UserModel.objects.get(username=username)
+ except UserModel.DoesNotExist:
return username
raise forms.ValidationError(self.error_messages['duplicate_username'])
@@ -121,7 +121,7 @@ def clean_password(self):
return self.initial["password"]
class Meta:
- model = User
+ model = UserModel
def __init__(self, *args, **kwargs):
super(UserChangeForm, self).__init__(*args, **kwargs)
@@ -199,8 +199,8 @@ def clean_email(self):
Validates that an active user exists with the given email address.
"""
email = self.cleaned_data["email"]
- self.users_cache = User.objects.filter(email__iexact=email,
- is_active=True)
+ self.users_cache = UserModel.objects.filter(email__iexact=email,
+ is_active=True)
if not len(self.users_cache):
raise forms.ValidationError(self.error_messages['unknown'])
if any((user.password == UNUSABLE_PASSWORD)

1 comment on commit 04ae518

@kunitoki

I think this or something on the line should be pushed to master...

Please sign in to comment.
Something went wrong with that request. Please try again.