Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19349 -- Fixed re-rendering of ReadOnlyPasswordHashWidget

Thanks tim.bowden at mapforge.com.au for the report, Andreas Hug
for the patch and Anton Baklanov for the review.
  • Loading branch information...
commit a0cd6dd11e81cd0e229d6d109524c8a7e52bc9e1 1 parent 84a5294
@claudep claudep authored
Showing with 26 additions and 2 deletions.
  1. +6 −1 django/contrib/auth/forms.py
  2. +20 −1 django/contrib/auth/tests/forms.py
View
7 django/contrib/auth/forms.py
@@ -27,7 +27,7 @@ def render(self, name, value, attrs):
encoded = value
final_attrs = self.build_attrs(attrs)
- if encoded == '' or encoded == UNUSABLE_PASSWORD:
+ if not encoded or encoded == UNUSABLE_PASSWORD:
summary = mark_safe("<strong>%s</strong>" % ugettext("No password set."))
else:
try:
@@ -52,6 +52,11 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault("required", False)
super(ReadOnlyPasswordHashField, self).__init__(*args, **kwargs)
+ def bound_data(self, data, initial):
+ # Always return initial because the widget doesn't
+ # render an input field.
+ return initial
+
class UserCreationForm(forms.ModelForm):
"""
View
21 django/contrib/auth/tests/forms.py
@@ -3,7 +3,8 @@
import os
from django.contrib.auth.models import User
from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm,
- PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm)
+ PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm,
+ ReadOnlyPasswordHashWidget)
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core import mail
from django.forms.fields import Field, EmailField
@@ -282,6 +283,14 @@ def test_bug_19133(self):
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['password'], 'sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161')
+ def test_bug_19349_bound_password_field(self):
+ user = User.objects.get(username='testclient')
+ form = UserChangeForm(data={}, instance=user)
+ # When rendering the bound password field,
+ # ReadOnlyPasswordHashWidget needs the initial
+ # value to render correctly
+ self.assertEqual(form.initial['password'], form['password'].value())
+
@skipIfCustomUser
@override_settings(USE_TZ=False, PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
@@ -362,3 +371,13 @@ def test_unusable_password(self):
self.assertFalse(form.is_valid())
self.assertEqual(form["email"].errors,
[_("The user account associated with this email address cannot reset the password.")])
+
+
+class ReadOnlyPasswordHashWidgetTest(TestCase):
+
+ def test_bug_19349_render_with_none_value(self):
+ # Rendering the widget with value set to None
+ # mustn't raise an exception.
+ widget = ReadOnlyPasswordHashWidget()
+ html = widget.render(name='password', value=None, attrs={})
+ self.assertIn(_("No password set."), html)
Please sign in to comment.
Something went wrong with that request. Please try again.