mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
newforms-admin: Changed Widget._has_changed to *only* use an empty string when data and/or initial is None. False values were tripping up the conditional.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7366 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
8cbcc7152b
commit
10f86fd1ee
@ -254,7 +254,6 @@ class BaseForm(StrAndUnicode):
|
||||
data_value = field.widget.value_from_datadict(self.data, self.files, prefixed_name)
|
||||
initial_value = self.initial.get(name, field.initial)
|
||||
if field.widget._has_changed(initial_value, data_value):
|
||||
#print field
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -172,8 +172,14 @@ class Widget(object):
|
||||
# For purposes of seeing whether something has changed, None is
|
||||
# the same as an empty string, if the data or inital value we get
|
||||
# is None, replace it w/ u''.
|
||||
data_value = data or u''
|
||||
initial_value = initial or u''
|
||||
if data is None:
|
||||
data_value = u''
|
||||
else:
|
||||
data_value = data
|
||||
if initial is None:
|
||||
initial_value = u''
|
||||
else:
|
||||
initial_value = initial
|
||||
if force_unicode(initial_value) != force_unicode(data_value):
|
||||
return True
|
||||
return False
|
||||
|
@ -1717,4 +1717,25 @@ Traceback (most recent call last):
|
||||
...
|
||||
AttributeError: 'SongForm' object has no attribute 'cleaned_data'
|
||||
|
||||
If a field is not given in the data then None is returned for its data. Lets
|
||||
make sure that when checking for empty_permitted that None is treated
|
||||
accordingly.
|
||||
|
||||
>>> data = {'artist': None, 'song': ''}
|
||||
>>> form = SongForm(data, empty_permitted=True)
|
||||
>>> form.is_valid()
|
||||
True
|
||||
|
||||
However, we *really* need to be sure we are checking for None as any data in
|
||||
initial that returns False on a boolean call needs to be treated literally.
|
||||
|
||||
>>> class PriceForm(Form):
|
||||
... amount = FloatField()
|
||||
... qty = IntegerField()
|
||||
|
||||
>>> data = {'amount': '0.0', 'qty': ''}
|
||||
>>> form = PriceForm(data, initial={'amount': 0.0}, empty_permitted=True)
|
||||
>>> form.is_valid()
|
||||
True
|
||||
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user