Skip to content

Commit

Permalink
Fixed #11860. Changed NullBooleanSelect's _has_changed method to repe…
Browse files Browse the repository at this point in the history
…ct differences between None and False. Thanks, matiasb.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12523 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jkocherhans committed Feb 23, 2010
1 parent f9c8615 commit 871a99c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions django/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,13 @@ def value_from_datadict(self, data, files, name):
False: False}.get(value, None)

def _has_changed(self, initial, data):
# Sometimes data or initial could be None or u'' which should be the
# same thing as False.
return bool(initial) != bool(data)
# For a NullBooleanSelect, None (unknown) and False (No)
# are not the same
if initial is not None:
initial = bool(initial)
if data is not None:
data = bool(data)
return initial != data

class SelectMultiple(Select):
def render(self, name, value, attrs=None, choices=()):
Expand Down
14 changes: 14 additions & 0 deletions tests/regressiontests/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@
<option value="2">Yes</option>
<option value="3" selected="selected">No</option>
</select>
>>> w._has_changed(False, None)
True
>>> w._has_changed(None, False)
True
>>> w._has_changed(None, None)
False
>>> w._has_changed(False, False)
False
>>> w._has_changed(True, False)
True
>>> w._has_changed(True, None)
True
>>> w._has_changed(True, True)
False
""" + \
r""" # [This concatenation is to keep the string below the jython's 32K limit].
Expand Down

0 comments on commit 871a99c

Please sign in to comment.