Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 6b31f95516e3a65f93a9ab6491c6e3b2b54ae620 1 parent a0137c4
Adrian Holovaty authored January 13, 2007
4  django/newforms/fields.py
@@ -114,11 +114,11 @@ def __init__(self, max_value=None, min_value=None, required=True, widget=None, l
114 114
     def clean(self, value):
115 115
         """
116 116
         Validates that int() can be called on the input. Returns the result
117  
-        of int().
  117
+        of int(). Returns None for empty values.
118 118
         """
119 119
         super(IntegerField, self).clean(value)
120 120
         if not self.required and value in EMPTY_VALUES:
121  
-            return u''
  121
+            return None
122 122
         try:
123 123
             value = int(value)
124 124
         except (ValueError, TypeError):
6  tests/regressiontests/forms/tests.py
@@ -810,9 +810,11 @@
810 810
 
811 811
 >>> f = IntegerField(required=False)
812 812
 >>> f.clean('')
813  
-u''
  813
+>>> repr(f.clean(''))
  814
+'None'
814 815
 >>> f.clean(None)
815  
-u''
  816
+>>> repr(f.clean(None))
  817
+'None'
816 818
 >>> f.clean('1')
817 819
 1
818 820
 >>> isinstance(f.clean('1'), int)

0 notes on commit 6b31f95

Please sign in to comment.
Something went wrong with that request. Please try again.