Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11860. Changed NullBooleanSelect's _has_changed method to repe…

…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...
commit 871a99c948bcfe7e59bf93df4bcd00cffcbf94f2 1 parent f9c8615
Joseph Kocherhans authored February 23, 2010
10  django/forms/widgets.py
@@ -452,9 +452,13 @@ def value_from_datadict(self, data, files, name):
452 452
                 False: False}.get(value, None)
453 453
 
454 454
     def _has_changed(self, initial, data):
455  
-        # Sometimes data or initial could be None or u'' which should be the
456  
-        # same thing as False.
457  
-        return bool(initial) != bool(data)
  455
+        # For a NullBooleanSelect, None (unknown) and False (No)
  456
+        # are not the same
  457
+        if initial is not None:
  458
+            initial = bool(initial)
  459
+        if data is not None:
  460
+            data = bool(data)
  461
+        return initial != data
458 462
 
459 463
 class SelectMultiple(Select):
460 464
     def render(self, name, value, attrs=None, choices=()):
14  tests/regressiontests/forms/widgets.py
@@ -532,6 +532,20 @@
532 532
 <option value="2">Yes</option>
533 533
 <option value="3" selected="selected">No</option>
534 534
 </select>
  535
+>>> w._has_changed(False, None)
  536
+True
  537
+>>> w._has_changed(None, False)
  538
+True
  539
+>>> w._has_changed(None, None)
  540
+False
  541
+>>> w._has_changed(False, False)
  542
+False
  543
+>>> w._has_changed(True, False)
  544
+True
  545
+>>> w._has_changed(True, None)
  546
+True
  547
+>>> w._has_changed(True, True)
  548
+False
535 549
 
536 550
 """ + \
537 551
 r""" # [This concatenation is to keep the string below the jython's 32K limit].

0 notes on commit 871a99c

Please sign in to comment.
Something went wrong with that request. Please try again.