Django

Code

Changeset 6745

Show
Ignore:
Timestamp:
11/29/07 13:22:03 (11 months ago)
Author:
mtredinnick
Message:

Fixed #5959 -- Fixed handling of False values in hidden boolean fields. Thanks,
SmileyChris?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/fields.py

    r6642 r6745  
    537537 
    538538    def clean(self, value): 
    539         "Returns a Python boolean object.
     539        """Returns a Python boolean object.""
    540540        super(BooleanField, self).clean(value) 
    541         # Explicitly check for the string '0', which is what as hidden field 
    542         # will submit for False. 
    543         if value == '0': 
     541        # Explicitly check for the string 'False', which is what a hidden field 
     542        # will submit for False (since bool("True") == True we don't need to 
     543        # handle that explicitly). 
     544        if value == 'False': 
    544545            return False 
    545546        return bool(value) 
  • django/trunk/tests/regressiontests/forms/fields.py

    r6379 r6745  
    915915True 
    916916 
     917>>> f.clean('True') 
     918True 
     919>>> f.clean('False') 
     920False 
     921 
    917922>>> f = BooleanField(required=False) 
    918923>>> f.clean('') 
     
    930935>>> f.clean('Django rocks') 
    931936True 
     937 
     938A form's BooleanField with a hidden widget will output the string 'False', so 
     939that should clean to the boolean value False: 
     940>>> f.clean('False') 
     941False 
    932942 
    933943# ChoiceField ################################################################# 
  • django/trunk/tests/regressiontests/forms/widgets.py

    r6722 r6745  
    129129>>> w.render('email', '', attrs={'class': 'special'}) 
    130130u'<input type="hidden" class="special" name="email" />' 
     131 
     132Boolean values are rendered to their string forms ("True" and "False"). 
     133>>> w = HiddenInput() 
     134>>> w.render('get_spam', False) 
     135u'<input type="hidden" name="get_spam" value="False" />' 
     136>>> w.render('get_spam', True) 
     137u'<input type="hidden" name="get_spam" value="True" />' 
    131138 
    132139# MultipleHiddenInput Widget ##################################################