Fixed #18460 -- Fixed change detection of ReadOnlyPasswordHashField

Thanks jose.sanchez et ezeep.com for the report and Vladimir Ulupov
for the initial patch.
This commit is contained in:
Claude Paroz 2013-01-25 21:27:49 +01:00
parent ebb504db69
commit 1686e0d184
2 changed files with 9 additions and 2 deletions

View File

@ -57,6 +57,9 @@ class ReadOnlyPasswordHashField(forms.Field):
# render an input field. # render an input field.
return initial return initial
def _has_changed(self, initial, data):
return False
class UserCreationForm(forms.ModelForm): class UserCreationForm(forms.ModelForm):
""" """

View File

@ -4,7 +4,7 @@ import os
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm, from django.contrib.auth.forms import (UserCreationForm, AuthenticationForm,
PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm, PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm,
ReadOnlyPasswordHashWidget) ReadOnlyPasswordHashField, ReadOnlyPasswordHashWidget)
from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.auth.tests.utils import skipIfCustomUser
from django.core import mail from django.core import mail
from django.forms.fields import Field, EmailField, CharField 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.")]) [_("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): def test_bug_19349_render_with_none_value(self):
# Rendering the widget with value set to None # Rendering the widget with value set to None
@ -392,3 +392,7 @@ class ReadOnlyPasswordHashWidgetTest(TestCase):
widget = ReadOnlyPasswordHashWidget() widget = ReadOnlyPasswordHashWidget()
html = widget.render(name='password', value=None, attrs={}) html = widget.render(name='password', value=None, attrs={})
self.assertIn(_("No password set."), html) self.assertIn(_("No password set."), html)
def test_readonly_field_has_changed(self):
field = ReadOnlyPasswordHashField()
self.assertFalse(field._has_changed('aaa', 'bbb'))