From 1686e0d184aaf704e5131a8651a070c4a0e58b03 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 25 Jan 2013 21:27:49 +0100 Subject: [PATCH] Fixed #18460 -- Fixed change detection of ReadOnlyPasswordHashField Thanks jose.sanchez et ezeep.com for the report and Vladimir Ulupov for the initial patch. --- django/contrib/auth/forms.py | 3 +++ django/contrib/auth/tests/forms.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index cbce8ad6e2..ee4fb482ce 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -57,6 +57,9 @@ class ReadOnlyPasswordHashField(forms.Field): # render an input field. return initial + def _has_changed(self, initial, data): + return False + class UserCreationForm(forms.ModelForm): """ diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py index 543bb2001d..0c0973d543 100644 --- a/django/contrib/auth/tests/forms.py +++ b/django/contrib/auth/tests/forms.py @@ -4,7 +4,7 @@ import os from django.contrib.auth.models import User from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm, PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm, - ReadOnlyPasswordHashWidget) + ReadOnlyPasswordHashField, ReadOnlyPasswordHashWidget) from django.contrib.auth.tests.utils import skipIfCustomUser from django.core import mail from django.forms.fields import Field, EmailField, CharField @@ -384,7 +384,7 @@ class PasswordResetFormTest(TestCase): [_("The user account associated with this email address cannot reset the password.")]) -class ReadOnlyPasswordHashWidgetTest(TestCase): +class ReadOnlyPasswordHashTest(TestCase): def test_bug_19349_render_with_none_value(self): # Rendering the widget with value set to None @@ -392,3 +392,7 @@ class ReadOnlyPasswordHashWidgetTest(TestCase): widget = ReadOnlyPasswordHashWidget() html = widget.render(name='password', value=None, attrs={}) self.assertIn(_("No password set."), html) + + def test_readonly_field_has_changed(self): + field = ReadOnlyPasswordHashField() + self.assertFalse(field._has_changed('aaa', 'bbb'))