diff options
| author | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-01-05 03:56:19 +0000 |
|---|---|---|
| committer | Joseph Kocherhans <joseph@jkocherhans.com> | 2010-01-05 03:56:19 +0000 |
| commit | 471596fc1afcb9c6258d317c619eaf5fd394e797 (patch) | |
| tree | 193767161be3cc23dc2e6be5e4f16d8fd21a2925 /django/contrib/auth/forms.py | |
| parent | 4e89105d64bb9e04c409139a41e9c7aac263df4c (diff) | |
Merged soc2009/model-validation to trunk. Thanks, Honza!
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12098 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/contrib/auth/forms.py')
| -rw-r--r-- | django/contrib/auth/forms.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 55e770e553..dbc55ca0f9 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -1,4 +1,4 @@ -from django.contrib.auth.models import User +from django.contrib.auth.models import User, UNUSABLE_PASSWORD from django.contrib.auth import authenticate from django.contrib.auth.tokens import default_token_generator from django.contrib.sites.models import Site @@ -21,6 +21,12 @@ class UserCreationForm(forms.ModelForm): model = User fields = ("username",) + def clean(self): + # Fill the password field so model validation won't complain about it + # being blank. We'll set it with the real value below. + self.instance.password = UNUSABLE_PASSWORD + super(UserCreationForm, self).clean() + def clean_username(self): username = self.cleaned_data["username"] try: @@ -34,15 +40,9 @@ class UserCreationForm(forms.ModelForm): password2 = self.cleaned_data["password2"] if password1 != password2: raise forms.ValidationError(_("The two password fields didn't match.")) + self.instance.set_password(password1) return password2 - def save(self, commit=True): - user = super(UserCreationForm, self).save(commit=False) - user.set_password(self.cleaned_data["password1"]) - if commit: - user.save() - return user - class UserChangeForm(forms.ModelForm): username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$', help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."), |
