Ticket #6937: patch.diff

File patch.diff, 1.2 KB (added by Andrew Gibson, 16 years ago)

one line change plus tests

  • trunk/django/forms/fields.py

     
    577577        # Explicitly check for the string 'False', which is what a hidden field
    578578        # will submit for False. Because bool("True") == True, we don't need to
    579579        # handle that explicitly.
    580         if value == 'False':
     580        if isinstance(value,str) and value.lower() in ('f', 'false', '0','no'):
    581581            value = False
    582582        else:
    583583            value = bool(value)
  • trunk/tests/regressiontests/forms/fields.py

     
    10111011False
    10121012>>> f.clean('Django rocks')
    10131013True
     1014>>> f.clean('f')
     1015False
     1016>>> f.clean('falSe')
     1017False
     1018>>> f.clean('FALSE')
     1019False
     1020>>> f.clean('0')
     1021False
     1022>>> f.clean('f')
     1023False
     1024>>> f.clean('no')
     1025False
     1026>>> f.clean('No')
     1027False
    10141028
    10151029A form's BooleanField with a hidden widget will output the string 'False', so
    10161030that should clean to the boolean value False:
Back to Top