Ticket #19349: 19349.diff

File 19349.diff, 1.5 KB (added by foonicorn, 3 years ago)

Override ReadOnlyPasswordHashField.bound_data to always return initial value

  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index 9279c52..e011d47 100644
    a b class ReadOnlyPasswordHashField(forms.Field): 
    5252        kwargs.setdefault("required", False)
    5353        super(ReadOnlyPasswordHashField, self).__init__(*args, **kwargs)
    5454
     55    def bound_data(self, data, initial):
     56        # Always return initial because the widget doesn't
     57        # render an input field.
     58        return initial
     59
    5560
    5661class UserCreationForm(forms.ModelForm):
    5762    """
  • django/contrib/auth/tests/forms.py

    diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
    index f3eb242..87fcfc8 100644
    a b class UserChangeFormTest(TestCase): 
    282282        self.assertTrue(form.is_valid())
    283283        self.assertEqual(form.cleaned_data['password'], 'sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161')
    284284
     285    def test_bug_19349_bound_password_field(self):
     286        user = User.objects.get(username='testclient')
     287        form = UserChangeForm(data={}, instance=user)
     288        # When rendering the bound password field,
     289        # ReadOnlyPasswordHashWidget needs the initial
     290        # value to render correctly
     291        self.assertEqual(form.initial['password'], form['password'].value())
     292
    285293
    286294@skipIfCustomUser
    287295@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
Back to Top