Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3303 -- Cleaned some newforms clean() method implementations. …

…Thanks for the patch, SmileyChris

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4367 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 230b746f6cc037f5eedfada35cb7a250f7f54992 1 parent 5e8c1a6
Adrian Holovaty authored January 20, 2007

Showing 1 changed file with 9 additions and 9 deletions. Show diff stats Hide diff stats

  1. 18  django/newforms/fields.py
18  django/newforms/fields.py
@@ -92,9 +92,7 @@ def clean(self, value):
92 92
         "Validates max_length and min_length. Returns a Unicode object."
93 93
         super(CharField, self).clean(value)
94 94
         if value in EMPTY_VALUES:
95  
-            value = u''
96  
-            if not self.required:
97  
-                return value
  95
+            return u''
98 96
         value = smart_unicode(value)
99 97
         if self.max_length is not None and len(value) > self.max_length:
100 98
             raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length)
@@ -117,7 +115,7 @@ def clean(self, value):
117 115
         of int(). Returns None for empty values.
118 116
         """
119 117
         super(IntegerField, self).clean(value)
120  
-        if not self.required and value in EMPTY_VALUES:
  118
+        if value in EMPTY_VALUES:
121 119
             return None
122 120
         try:
123 121
             value = int(value)
@@ -245,9 +243,10 @@ def clean(self, value):
245 243
         Unicode object.
246 244
         """
247 245
         super(RegexField, self).clean(value)
248  
-        if value in EMPTY_VALUES: value = u''
  246
+        if value in EMPTY_VALUES:
  247
+            value = u''
249 248
         value = smart_unicode(value)
250  
-        if not self.required and value == u'':
  249
+        if value == u'':
251 250
             return value
252 251
         if self.max_length is not None and len(value) > self.max_length:
253 252
             raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length)
@@ -288,7 +287,7 @@ def __init__(self, max_length=None, min_length=None, required=True, verify_exist
288 287
 
289 288
     def clean(self, value):
290 289
         value = super(URLField, self).clean(value)
291  
-        if not self.required and value == u'':
  290
+        if value == u'':
292 291
             return value
293 292
         if self.verify_exists:
294 293
             import urllib2
@@ -329,9 +328,10 @@ def clean(self, value):
329 328
         Validates that the input is in self.choices.
330 329
         """
331 330
         value = super(ChoiceField, self).clean(value)
332  
-        if value in EMPTY_VALUES: value = u''
  331
+        if value in EMPTY_VALUES:
  332
+            value = u''
333 333
         value = smart_unicode(value)
334  
-        if not self.required and value == u'':
  334
+        if value == u'':
335 335
             return value
336 336
         valid_values = set([str(k) for k, v in self.choices])
337 337
         if value not in valid_values:

0 notes on commit 230b746

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