Ticket #7753: nullbool_clean.diff
File nullbool_clean.diff, 1.5 KB (added by , 16 years ago) |
---|
-
django/newforms/fields.py
582 582 widget = NullBooleanSelect 583 583 584 584 def clean(self, value): 585 return {True: True, False: False}.get(value, None) 585 """Returns a Python boolean object OR None""" 586 # Explicitly check for the string 'True' and 'False', which is what a 587 # hidden field will submit for True and False. Unlike the 588 # Booleanfield we also need to check for True, because we are not using 589 # the bool() function 590 if value in [True, 'True']: 591 return True 592 elif value in [False, 'False']: 593 return False 594 else: 595 return None 586 596 587 597 class ChoiceField(Field): 588 598 widget = Select -
tests/regressiontests/forms/fields.py
1034 1034 >>> f.clean('3') 1035 1035 >>> f.clean('hello') 1036 1036 1037 A form's NullBooleanField with a hidden widget will output the string 'True' 1038 for True and 'False' for False, so those should be cleaned to their respective 1039 Python values 1040 >>> f.clean('True') 1041 True 1042 >>> f.clean('False') 1043 False 1044 1037 1045 # MultipleChoiceField ######################################################### 1038 1046 1039 1047 >>> f = MultipleChoiceField(choices=[('1', '1'), ('2', '2')])