Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Slightly improved the help text for the "Password" field in the `auth…

….User` admin form, and PEP8-cleaned up the area while I was there.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17326 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 991d3d6c12296b381959ae86e74fd505604daeac 1 parent cb99b59
@jphalip jphalip authored
Showing with 58 additions and 30 deletions.
  1. +58 −30 django/contrib/auth/forms.py
View
88 django/contrib/auth/forms.py
@@ -51,17 +51,24 @@ def __init__(self, *args, **kwargs):
class UserCreationForm(forms.ModelForm):
"""
- A form that creates a user, with no privileges, from the given username and password.
+ A form that creates a user, with no privileges, from the given username and
+ password.
"""
error_messages = {
'duplicate_username': _("A user with that username already exists."),
'password_mismatch': _("The two password fields didn't match."),
}
- username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
- help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
- error_messages = {'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
- password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
- password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput,
+ username = forms.RegexField(label=_("Username"), max_length=30,
+ regex=r'^[\w.@+-]+$',
+ help_text = _("Required. 30 characters or fewer. Letters, digits and "
+ "@/./+/-/_ only."),
+ error_messages = {
+ 'invalid': _("This value may contain only letters, numbers and "
+ "@/./+/-/_ characters.")})
+ password1 = forms.CharField(label=_("Password"),
+ widget=forms.PasswordInput)
+ password2 = forms.CharField(label=_("Password confirmation"),
+ widget=forms.PasswordInput,
help_text = _("Enter the same password as above, for verification."))
class Meta:
@@ -82,7 +89,8 @@ def clean_password2(self):
password1 = self.cleaned_data.get("password1", "")
password2 = self.cleaned_data["password2"]
if password1 != password2:
- raise forms.ValidationError(self.error_messages['password_mismatch'])
+ raise forms.ValidationError(
+ self.error_messages['password_mismatch'])
return password2
def save(self, commit=True):
@@ -94,10 +102,17 @@ def save(self, commit=True):
class UserChangeForm(forms.ModelForm):
- username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
- help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
- error_messages = {'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
- password = ReadOnlyPasswordHashField(label=_("Password"), help_text=_("We don't store raw passwords, so there's no way to see this user's password, but you can change the password using <a href=\"password/\">this form</a>."))
+ username = forms.RegexField(
+ label=_("Username"), max_length=30, regex=r"^[\w.@+-]+$",
+ help_text = _("Required. 30 characters or fewer. Letters, digits and "
+ "@/./+/-/_ only."),
+ error_messages = {
+ 'invalid': _("This value may contain only letters, numbers and "
+ "@/./+/-/_ characters.")})
+ password = ReadOnlyPasswordHashField(label=_("Password"),
+ help_text=_("Raw passwords are not stored, so there is no way to see "
+ "this user's password, but you can change the password "
+ "using <a href=\"password/\">this form</a>."))
def clean_password(self):
return self.initial["password"]
@@ -144,9 +159,11 @@ def clean(self):
password = self.cleaned_data.get('password')
if username and password:
- self.user_cache = authenticate(username=username, password=password)
+ self.user_cache = authenticate(username=username,
+ password=password)
if self.user_cache is None:
- raise forms.ValidationError(self.error_messages['invalid_login'])
+ raise forms.ValidationError(
+ self.error_messages['invalid_login'])
elif not self.user_cache.is_active:
raise forms.ValidationError(self.error_messages['inactive'])
self.check_for_test_cookie()
@@ -179,12 +196,12 @@ 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 = User.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) for user in self.users_cache):
+ if any((user.password == UNUSABLE_PASSWORD)
+ for user in self.users_cache):
raise forms.ValidationError(self.error_messages['unusable'])
return email
@@ -194,7 +211,8 @@ def save(self, domain_override=None,
use_https=False, token_generator=default_token_generator,
from_email=None, request=None):
"""
- Generates a one-use only link for resetting password and sends to the user
+ Generates a one-use only link for resetting password and sends to the
+ user.
"""
from django.core.mail import send_mail
for user in self.users_cache:
@@ -222,14 +240,16 @@ def save(self, domain_override=None,
class SetPasswordForm(forms.Form):
"""
- A form that lets a user change set his/her password without
- entering the old password
+ A form that lets a user change set his/her password without entering the
+ old password
"""
error_messages = {
'password_mismatch': _("The two password fields didn't match."),
}
- new_password1 = forms.CharField(label=_("New password"), widget=forms.PasswordInput)
- new_password2 = forms.CharField(label=_("New password confirmation"), widget=forms.PasswordInput)
+ new_password1 = forms.CharField(label=_("New password"),
+ widget=forms.PasswordInput)
+ new_password2 = forms.CharField(label=_("New password confirmation"),
+ widget=forms.PasswordInput)
def __init__(self, user, *args, **kwargs):
self.user = user
@@ -240,7 +260,8 @@ def clean_new_password2(self):
password2 = self.cleaned_data.get('new_password2')
if password1 and password2:
if password1 != password2:
- raise forms.ValidationError(self.error_messages['password_mismatch'])
+ raise forms.ValidationError(
+ self.error_messages['password_mismatch'])
return password2
def save(self, commit=True):
@@ -256,9 +277,11 @@ class PasswordChangeForm(SetPasswordForm):
their old password.
"""
error_messages = dict(SetPasswordForm.error_messages, **{
- 'password_incorrect': _("Your old password was entered incorrectly. Please enter it again."),
+ 'password_incorrect': _("Your old password was entered incorrectly. "
+ "Please enter it again."),
})
- old_password = forms.CharField(label=_("Old password"), widget=forms.PasswordInput)
+ old_password = forms.CharField(label=_("Old password"),
+ widget=forms.PasswordInput)
def clean_old_password(self):
"""
@@ -266,9 +289,11 @@ def clean_old_password(self):
"""
old_password = self.cleaned_data["old_password"]
if not self.user.check_password(old_password):
- raise forms.ValidationError(self.error_messages['password_incorrect'])
+ raise forms.ValidationError(
+ self.error_messages['password_incorrect'])
return old_password
-PasswordChangeForm.base_fields.keyOrder = ['old_password', 'new_password1', 'new_password2']
+PasswordChangeForm.base_fields.keyOrder = ['old_password', 'new_password1',
+ 'new_password2']
class AdminPasswordChangeForm(forms.Form):
@@ -278,8 +303,10 @@ class AdminPasswordChangeForm(forms.Form):
error_messages = {
'password_mismatch': _("The two password fields didn't match."),
}
- password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
- password2 = forms.CharField(label=_("Password (again)"), widget=forms.PasswordInput)
+ password1 = forms.CharField(label=_("Password"),
+ widget=forms.PasswordInput)
+ password2 = forms.CharField(label=_("Password (again)"),
+ widget=forms.PasswordInput)
def __init__(self, user, *args, **kwargs):
self.user = user
@@ -290,7 +317,8 @@ def clean_password2(self):
password2 = self.cleaned_data.get('password2')
if password1 and password2:
if password1 != password2:
- raise forms.ValidationError(self.error_messages['password_mismatch'])
+ raise forms.ValidationError(
+ self.error_messages['password_mismatch'])
return password2
def save(self, commit=True):
Please sign in to comment.
Something went wrong with that request. Please try again.