summaryrefslogtreecommitdiff
path: root/tests/regressiontests/forms/fields.py
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2009-05-02 14:52:34 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2009-05-02 14:52:34 +0000
commitf6cca736a0e1a0ac19e65fb52fa224c1c0d258fd (patch)
treea1899daef52a0f24fab500df43e41a30dbb06e7a /tests/regressiontests/forms/fields.py
parent95bcb70b5624a22cfc29795ea363e4a42fce6638 (diff)
Fixed #9609 -- Modified the clean method of(Null)Boolean field to accept '1' and '0' as valid inputs. Thanks to psagers for the patch.
This is required to support the use of non-default form widgets such as RadioSelect when the data comes from MySQL, which uses 1/0 to represent booleans. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10660 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms/fields.py')
-rw-r--r--tests/regressiontests/forms/fields.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index f66f2e1bb5..9d9d7227b9 100644
--- a/tests/regressiontests/forms/fields.py
+++ b/tests/regressiontests/forms/fields.py
@@ -1077,6 +1077,10 @@ False
True
>>> f.clean(0)
False
+>>> f.clean('1')
+True
+>>> f.clean('0')
+False
>>> f.clean('Django rocks')
True
@@ -1201,7 +1205,10 @@ True
>>> f.clean(False)
False
>>> f.clean(None)
+>>> f.clean('0')
+False
>>> f.clean('1')
+True
>>> f.clean('2')
>>> f.clean('3')
>>> f.clean('hello')
@@ -1220,6 +1227,21 @@ True
>>> f.cleaned_data['hidden_nullbool2']
False
+# Make sure we're compatible with MySQL, which uses 0 and 1 for its boolean
+# values. (#9609)
+>>> NULLBOOL_CHOICES = (('1', 'Yes'), ('0', 'No'), ('', 'Unknown'))
+>>> class MySQLNullBooleanForm(Form):
+... nullbool0 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES))
+... nullbool1 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES))
+... nullbool2 = NullBooleanField(widget=RadioSelect(choices=NULLBOOL_CHOICES))
+>>> f = MySQLNullBooleanForm({ 'nullbool0': '1', 'nullbool1': '0', 'nullbool2': '' })
+>>> f.full_clean()
+>>> f.cleaned_data['nullbool0']
+True
+>>> f.cleaned_data['nullbool1']
+False
+>>> f.cleaned_data['nullbool2']
+
# MultipleChoiceField #########################################################
>>> f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])