diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index dfe46a2..8e119e7 100644
|
a
|
b
|
class Field(object):
|
| 101 | 101 | |
| 102 | 102 | Raises ValidationError for any errors. |
| 103 | 103 | """ |
| | 104 | from operator import or_ |
| 104 | 105 | if self.required and value in EMPTY_VALUES: |
| 105 | 106 | raise ValidationError(self.error_messages['required']) |
| 106 | 107 | return value |
| … |
… |
class BooleanField(Field):
|
| 535 | 536 | |
| 536 | 537 | def clean(self, value): |
| 537 | 538 | """Returns a Python boolean object.""" |
| | 539 | if value == 'False': |
| | 540 | value = False |
| 538 | 541 | super(BooleanField, self).clean(value) |
| 539 | 542 | # Explicitly check for the string 'False', which is what a hidden field |
| 540 | 543 | # will submit for False. Because bool("True") == True, we don't need to |
| 541 | 544 | # handle that explicitly. |
| 542 | | if value == 'False': |
| 543 | | return False |
| | 545 | if not bool(value) and self.required: |
| | 546 | raise ValidationError(self.error_messages['required']) |
| 544 | 547 | return bool(value) |
| 545 | 548 | |
| 546 | 549 | class NullBooleanField(BooleanField): |
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index f3b6a96..207ff80 100644
|
a
|
b
|
ValidationError: [u'This field is required.']
|
| 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('') |