Fixed #13770 -- Extended BooleanField form field to also clean `u'false'` to `False`. Thanks, jordanb and Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16148 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-05-03 11:52:30 +00:00
parent f4860448dd
commit 8ce352c21d
2 changed files with 3 additions and 1 deletions

View File

@ -605,7 +605,7 @@ class BooleanField(Field):
# will submit for False. Also check for '0', since this is what
# RadioSelect will provide. Because bool("True") == bool('1') == True,
# we don't need to handle that explicitly.
if value in ('False', '0'):
if isinstance(value, basestring) and value.lower() in ('false', '0'):
value = False
else:
value = bool(value)

View File

@ -698,6 +698,8 @@ class FieldsTests(TestCase):
self.assertEqual(False, f.clean('0'))
self.assertEqual(True, f.clean('Django rocks'))
self.assertEqual(False, f.clean('False'))
self.assertEqual(False, f.clean('false'))
self.assertEqual(False, f.clean('FaLsE'))
# ChoiceField #################################################################