diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 9279c52..673c044 100644
|
a
|
b
|
class ReadOnlyPasswordHashWidget(forms.Widget):
|
| 27 | 27 | encoded = value |
| 28 | 28 | final_attrs = self.build_attrs(attrs) |
| 29 | 29 | |
| 30 | | if encoded == '' or encoded == UNUSABLE_PASSWORD: |
| | 30 | if not encoded or encoded == UNUSABLE_PASSWORD: |
| 31 | 31 | summary = mark_safe("<strong>%s</strong>" % ugettext("No password set.")) |
| 32 | 32 | else: |
| 33 | 33 | try: |
| … |
… |
class ReadOnlyPasswordHashField(forms.Field):
|
| 52 | 52 | kwargs.setdefault("required", False) |
| 53 | 53 | super(ReadOnlyPasswordHashField, self).__init__(*args, **kwargs) |
| 54 | 54 | |
| | 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 | |
| 55 | 60 | |
| 56 | 61 | class UserCreationForm(forms.ModelForm): |
| 57 | 62 | """ |
diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
index f3eb242..1306619 100644
|
a
|
b
|
from __future__ import unicode_literals
|
| 3 | 3 | import os |
| 4 | 4 | from django.contrib.auth.models import User |
| 5 | 5 | from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm, |
| 6 | | PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm) |
| | 6 | PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm, |
| | 7 | ReadOnlyPasswordHashWidget) |
| 7 | 8 | from django.contrib.auth.tests.utils import skipIfCustomUser |
| 8 | 9 | from django.core import mail |
| 9 | 10 | from django.forms.fields import Field, EmailField |
| … |
… |
class UserChangeFormTest(TestCase):
|
| 282 | 283 | self.assertTrue(form.is_valid()) |
| 283 | 284 | self.assertEqual(form.cleaned_data['password'], 'sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161') |
| 284 | 285 | |
| | 286 | def test_bug_19349_bound_password_field(self): |
| | 287 | user = User.objects.get(username='testclient') |
| | 288 | form = UserChangeForm(data={}, instance=user) |
| | 289 | # When rendering the bound password field, |
| | 290 | # ReadOnlyPasswordHashWidget needs the initial |
| | 291 | # value to render correctly |
| | 292 | self.assertEqual(form.initial['password'], form['password'].value()) |
| | 293 | |
| 285 | 294 | |
| 286 | 295 | @skipIfCustomUser |
| 287 | 296 | @override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) |
| … |
… |
class PasswordResetFormTest(TestCase):
|
| 362 | 371 | self.assertFalse(form.is_valid()) |
| 363 | 372 | self.assertEqual(form["email"].errors, |
| 364 | 373 | [_("The user account associated with this email address cannot reset the password.")]) |
| | 374 | |
| | 375 | |
| | 376 | class ReadOnlyPasswordHashWidgetTest(TestCase): |
| | 377 | |
| | 378 | def test_bug_19349_render_with_none_value(self): |
| | 379 | # Rendering the widget with value set to None |
| | 380 | # mustn't raise an exception. |
| | 381 | widget = ReadOnlyPasswordHashWidget() |
| | 382 | html = widget.render(name='password', value=None, attrs={}) |
| | 383 | self.assertTrue(html) |