Ticket #5957: bool.3.diff

File bool.3.diff, 1.6 KB (added by Alex Gaynor, 16 years ago)

tiny style fix

  • django/newforms/fields.py

    diff --git a/django/newforms/fields.py b/django/newforms/fields.py
    index dfe46a2..337a689 100644
    a b class BooleanField(Field):  
    535535
    536536    def clean(self, value):
    537537        """Returns a Python boolean object."""
     538        if value == 'False':
     539            value = False
    538540        super(BooleanField, self).clean(value)
    539541        # Explicitly check for the string 'False', which is what a hidden field
    540542        # will submit for False. Because bool("True") == True, we don't need to
    541543        # handle that explicitly.
    542         if value == 'False':
    543             return False
     544        if not value and self.required:
     545            raise ValidationError(self.error_messages['required'])
    544546        return bool(value)
    545547
    546548class NullBooleanField(BooleanField):
  • tests/regressiontests/forms/fields.py

    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.']  
    937937>>> f.clean(True)
    938938True
    939939>>> f.clean(False)
    940 False
     940Traceback (most recent call last):
     941...
     942ValidationError: [u'This field is required.']
    941943>>> f.clean(1)
    942944True
    943945>>> f.clean(0)
    944 False
     946Traceback (most recent call last):
     947...
     948ValidationError: [u'This field is required.']
    945949>>> f.clean('Django rocks')
    946950True
    947951
    948952>>> f.clean('True')
    949953True
    950954>>> f.clean('False')
    951 False
     955Traceback (most recent call last):
     956...
     957ValidationError: [u'This field is required.']
    952958
    953959>>> f = BooleanField(required=False)
    954960>>> f.clean('')
Back to Top