Changeset 6745
- Timestamp:
- 11/29/07 13:22:03 (11 months ago)
- Files:
-
- django/trunk/django/newforms/fields.py (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/fields.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/forms/widgets.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/fields.py
r6642 r6745 537 537 538 538 def clean(self, value): 539 " Returns a Python boolean object."539 """Returns a Python boolean object.""" 540 540 super(BooleanField, self).clean(value) 541 # Explicitly check for the string '0', which is what as hidden field 542 # will submit for False. 543 if value == '0': 541 # Explicitly check for the string 'False', which is what a hidden field 542 # will submit for False (since bool("True") == True we don't need to 543 # handle that explicitly). 544 if value == 'False': 544 545 return False 545 546 return bool(value) django/trunk/tests/regressiontests/forms/fields.py
r6379 r6745 915 915 True 916 916 917 >>> f.clean('True') 918 True 919 >>> f.clean('False') 920 False 921 917 922 >>> f = BooleanField(required=False) 918 923 >>> f.clean('') … … 930 935 >>> f.clean('Django rocks') 931 936 True 937 938 A form's BooleanField with a hidden widget will output the string 'False', so 939 that should clean to the boolean value False: 940 >>> f.clean('False') 941 False 932 942 933 943 # ChoiceField ################################################################# django/trunk/tests/regressiontests/forms/widgets.py
r6722 r6745 129 129 >>> w.render('email', '', attrs={'class': 'special'}) 130 130 u'<input type="hidden" class="special" name="email" />' 131 132 Boolean values are rendered to their string forms ("True" and "False"). 133 >>> w = HiddenInput() 134 >>> w.render('get_spam', False) 135 u'<input type="hidden" name="get_spam" value="False" />' 136 >>> w.render('get_spam', True) 137 u'<input type="hidden" name="get_spam" value="True" />' 131 138 132 139 # MultipleHiddenInput Widget ##################################################
