From 6b31f95516e3a65f93a9ab6491c6e3b2b54ae620 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 13 Jan 2007 05:08:07 +0000 Subject: [PATCH] Fixed #3293 -- newforms: Changed IntegerField.clean() to return None if field is not required and empty. Thanks, Honza Kral git-svn-id: http://code.djangoproject.com/svn/django/trunk@4312 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/fields.py | 4 ++-- tests/regressiontests/forms/tests.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/django/newforms/fields.py b/django/newforms/fields.py index e3c1cee87a..0b883bfad1 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -114,11 +114,11 @@ class IntegerField(Field): def clean(self, value): """ Validates that int() can be called on the input. Returns the result - of int(). + of int(). Returns None for empty values. """ super(IntegerField, self).clean(value) if not self.required and value in EMPTY_VALUES: - return u'' + return None try: value = int(value) except (ValueError, TypeError): diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 7ad6ffb98a..bfe36a467e 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -810,9 +810,11 @@ ValidationError: [u'Enter a whole number.'] >>> f = IntegerField(required=False) >>> f.clean('') -u'' +>>> repr(f.clean('')) +'None' >>> f.clean(None) -u'' +>>> repr(f.clean(None)) +'None' >>> f.clean('1') 1 >>> isinstance(f.clean('1'), int)