summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2010-02-23 14:17:42 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2010-02-23 14:17:42 +0000
commit871a99c948bcfe7e59bf93df4bcd00cffcbf94f2 (patch)
treecafb89407007c96fb7c436ca6515f441aef819a8
parentf9c8615e1fbd6490d566f179e5fc3bf18ce51268 (diff)
Fixed #11860. Changed NullBooleanSelect's _has_changed method to repect differences between None and False. Thanks, matiasb.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12523 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/forms/widgets.py10
-rw-r--r--tests/regressiontests/forms/widgets.py14
2 files changed, 21 insertions, 3 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 8b036bacd2..57bdea17f4 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -452,9 +452,13 @@ class NullBooleanSelect(Select):
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=()):
diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
index d909c0f26c..4acaf831aa 100644
--- a/tests/regressiontests/forms/widgets.py
+++ b/tests/regressiontests/forms/widgets.py
@@ -532,6 +532,20 @@ Choices can be nested one level in order to create HTML optgroups:
<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].