Ticket #7753: 7753.nullboolean.diff
File 7753.nullboolean.diff, 2.0 KB (added by , 16 years ago) |
---|
-
django/django/forms/fields.py
594 594 widget = NullBooleanSelect 595 595 596 596 def clean(self, value): 597 return {True: True, False: False}.get(value, None) 597 """ 598 Explicitly checks for the string 'True' and 'False', which is what a 599 hidden field will submit for True and False. Unlike the 600 Booleanfield we also need to check for True, because we are not using 601 the bool() function 602 """ 603 if value in (True, 'True'): 604 return True 605 elif value in (False, 'False'): 606 return False 607 else: 608 return None 598 609 599 610 class ChoiceField(Field): 600 611 widget = Select -
django/tests/regressiontests/forms/fields.py
1091 1091 >>> f.clean('3') 1092 1092 >>> f.clean('hello') 1093 1093 1094 # Make sure that the internal value is preserved if using HiddenInput (#7753) 1095 >>> class HiddenNullBooleanForm(Form): 1096 ... hidden_nullbool1 = NullBooleanField(widget=HiddenInput, initial=True) 1097 ... hidden_nullbool2 = NullBooleanField(widget=HiddenInput, initial=False) 1098 >>> f = HiddenNullBooleanForm() 1099 >>> print f 1100 <input type="hidden" name="hidden_nullbool1" value="True" id="id_hidden_nullbool1" /><input type="hidden" name="hidden_nullbool2" value="False" id="id_hidden_nullbool2" /> 1101 >>> f = HiddenNullBooleanForm({ 'hidden_nullbool1': 'True', 'hidden_nullbool2': 'False' }) 1102 >>> f.full_clean() 1103 >>> f.cleaned_data['hidden_nullbool1'] 1104 True 1105 >>> f.cleaned_data['hidden_nullbool2'] 1106 False 1107 1094 1108 # MultipleChoiceField ######################################################### 1095 1109 1096 1110 >>> f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])