Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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 authored January 10, 2013 claudep committed January 10, 2013
3  django/contrib/auth/forms.py
@@ -169,7 +169,8 @@ def __init__(self, request=None, *args, **kwargs):
169 169
         # Set the label for the "username" field.
170 170
         UserModel = get_user_model()
171 171
         self.username_field = UserModel._meta.get_field(UserModel.USERNAME_FIELD)
172  
-        self.fields['username'].label = capfirst(self.username_field.verbose_name)
  172
+        if not self.fields['username'].label:
  173
+            self.fields['username'].label = capfirst(self.username_field.verbose_name)
173 174
 
174 175
     def clean(self):
175 176
         username = self.cleaned_data.get('username')
10  django/contrib/auth/tests/forms.py
@@ -7,7 +7,7 @@
7 7
     ReadOnlyPasswordHashWidget)
8 8
 from django.contrib.auth.tests.utils import skipIfCustomUser
9 9
 from django.core import mail
10  
-from django.forms.fields import Field, EmailField
  10
+from django.forms.fields import Field, EmailField, CharField
11 11
 from django.test import TestCase
12 12
 from django.test.utils import override_settings
13 13
 from django.utils.encoding import force_text
@@ -138,6 +138,14 @@ def test_success(self):
138 138
         self.assertTrue(form.is_valid())
139 139
         self.assertEqual(form.non_field_errors(), [])
140 140
 
  141
+    def test_username_field_label(self):
  142
+
  143
+        class CustomAuthenticationForm(AuthenticationForm):
  144
+            username = CharField(label="Name", max_length=75)
  145
+
  146
+        form = CustomAuthenticationForm()
  147
+        self.assertEqual(form['username'].label, "Name")
  148
+
141 149
 
142 150
 @skipIfCustomUser
143 151
 @override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))

0 notes on commit b4544db

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