Ticket #7753: nullbool_clean.diff

File nullbool_clean.diff, 1.5 KB (added by ElliottM, 16 years ago)

fixed a tabbing thing

  • django/newforms/fields.py

     
    582582    widget = NullBooleanSelect
    583583
    584584    def clean(self, value):
    585         return {True: True, False: False}.get(value, None)
     585        """Returns a Python boolean object OR None"""
     586        # Explicitly check for the string 'True' and 'False', which is what a
     587        # hidden field will submit for True and False. Unlike the
     588        # Booleanfield we also need to check for True, because we are not using
     589        # the bool() function
     590        if value in [True, 'True']:
     591            return True
     592        elif value in [False, 'False']:
     593            return False
     594        else:
     595            return None
    586596
    587597class ChoiceField(Field):
    588598    widget = Select
  • tests/regressiontests/forms/fields.py

     
    10341034>>> f.clean('3')
    10351035>>> f.clean('hello')
    10361036
     1037A form's NullBooleanField with a hidden widget will output the string 'True'
     1038for True and 'False' for False, so those should be cleaned to their respective
     1039Python values
     1040>>> f.clean('True')
     1041True
     1042>>> f.clean('False')
     1043False
     1044
    10371045# MultipleChoiceField #########################################################
    10381046
    10391047>>> f = MultipleChoiceField(choices=[('1', '1'), ('2', '2')])
Back to Top