Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.5.x] Fixed #19573 -- Allow override of username field label in Aut…

…henticationForm

Backport of cdad0b2 from master.
  • Loading branch information...
commit b4544dbd5bf7fec73d03f31c0e59135d64fd818c 1 parent f9604c8
Nick Sandford slurms authored claudep committed
3  django/contrib/auth/forms.py
View
@@ -169,7 +169,8 @@ def __init__(self, request=None, *args, **kwargs):
# Set the label for the "username" field.
UserModel = get_user_model()
self.username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD)
- self.fields['username'].label = capfirst(self.username_field.verbose_name)
+ if not self.fields['username'].label:
+ self.fields['username'].label = capfirst(self.username_field.verbose_name)
def clean(self):
username = self.cleaned_data.get('username')
10 django/contrib/auth/tests/forms.py
View
@@ -7,7 +7,7 @@
ReadOnlyPasswordHashWidget)
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core import mail
-from django.forms.fields import Field, EmailField
+from django.forms.fields import Field, EmailField, CharField
from django.test import TestCase
from django.test.utils import override_settings
from django.utils.encoding import force_text
@@ -138,6 +138,14 @@ def test_success(self):
self.assertTrue(form.is_valid())
self.assertEqual(form.non_field_errors(), [])
+ def test_username_field_label(self):
+
+ class CustomAuthenticationForm(AuthenticationForm):
+ username = CharField(label="Name", max_length=75)
+
+ form = CustomAuthenticationForm()
+ self.assertEqual(form['username'].label, "Name")
+
@skipIfCustomUser
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
Please sign in to comment.
Something went wrong with that request. Please try again.