Ticket #5957: bool.2.diff
| File bool.2.diff, 1.6 kB (added by Alex, 2 years ago) |
|---|
-
a/django/newforms/fields.py
old new 535 535 536 536 def clean(self, value): 537 537 """Returns a Python boolean object.""" 538 if value == 'False': 539 value = False 538 540 super(BooleanField, self).clean(value) 539 541 # Explicitly check for the string 'False', which is what a hidden field 540 542 # will submit for False. Because bool("True") == True, we don't need to 541 543 # handle that explicitly. 542 if value == 'False':543 r eturn False544 if not bool(value) and self.required: 545 raise ValidationError(self.error_messages['required']) 544 546 return bool(value) 545 547 546 548 class NullBooleanField(BooleanField): -
a/tests/regressiontests/forms/fields.py
old new 937 937 >>> f.clean(True) 938 938 True 939 939 >>> f.clean(False) 940 False 940 Traceback (most recent call last): 941 ... 942 ValidationError: [u'This field is required.'] 941 943 >>> f.clean(1) 942 944 True 943 945 >>> f.clean(0) 944 False 946 Traceback (most recent call last): 947 ... 948 ValidationError: [u'This field is required.'] 945 949 >>> f.clean('Django rocks') 946 950 True 947 951 948 952 >>> f.clean('True') 949 953 True 950 954 >>> f.clean('False') 951 False 955 Traceback (most recent call last): 956 ... 957 ValidationError: [u'This field is required.'] 952 958 953 959 >>> f = BooleanField(required=False) 954 960 >>> f.clean('')
