mirror of
https://github.com/django/django.git
synced 2025-07-07 19:29:12 +00:00
[soc2009/model-validation] UserCreationForm made easier
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@10873 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a094bda10a
commit
a6a8ae6408
@ -34,15 +34,9 @@ class UserCreationForm(forms.ModelForm):
|
|||||||
password2 = self.cleaned_data["password2"]
|
password2 = self.cleaned_data["password2"]
|
||||||
if password1 != password2:
|
if password1 != password2:
|
||||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||||
|
self.instance.set_password(password1)
|
||||||
return password2
|
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):
|
class UserChangeForm(forms.ModelForm):
|
||||||
username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^\w+$',
|
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)."),
|
help_text = _("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user