Ticket #5957: newforms-booleanfield-required-tests.patch

File newforms-booleanfield-required-tests.patch, 1.1 KB (added by anonymous, 12 years ago)

Updated patch and tests

  • django/newforms/fields.py

     
    536536        # will submit for False. Because bool("True") == True, we don't need to
    537537        # handle that explicitly.
    538538        if value == 'False':
    539             return False
     539            value = False
     540        if self.required and not value:
     541            raise ValidationError(self.error_messages['required'])
    540542        return bool(value)
    541543
    542544class NullBooleanField(BooleanField):
  • tests/regressiontests/forms/tests.py

     
    16941694>>> f.clean(True)
    16951695True
    16961696>>> f.clean(False)
    1697 False
     1697Traceback (most recent call last):
     1698...
     1699ValidationError: [u'This field is required.']
    16981700>>> f.clean(1)
    16991701True
    17001702>>> f.clean(0)
    1701 False
     1703Traceback (most recent call last):
     1704...
     1705ValidationError: [u'This field is required.']
    17021706>>> f.clean('Django rocks')
    17031707True
    17041708
Back to Top