Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 adrianholovaty authored
Showing with 9 additions and 9 deletions.
  1. +9 −9 django/newforms/fields.py
18 django/newforms/fields.py
View
@@ -92,9 +92,7 @@ def clean(self, value):
"Validates max_length and min_length. Returns a Unicode object."
super(CharField, self).clean(value)
if value in EMPTY_VALUES:
- value = u''
- if not self.required:
- return value
+ return u''
value = smart_unicode(value)
if self.max_length is not None and len(value) > self.max_length:
raise ValidationError(gettext(u'Ensure this value has at most %d characters.') % self.max_length)
@@ -117,7 +115,7 @@ def clean(self, value):
of int(). Returns None for empty values.
"""
super(IntegerField, self).clean(value)
- if not self.required and value in EMPTY_VALUES:
+ if value in EMPTY_VALUES:
return None
try:
value = int(value)
@@ -245,9 +243,10 @@ def clean(self, value):
Unicode object.
"""
super(RegexField, self).clean(value)
- if value in EMPTY_VALUES: value = u''
+ if value in EMPTY_VALUES:
+ value = u''
value = smart_unicode(value)
- if not self.required and value == u'':
+ if value == u'':
return value
if self.max_length is not None and len(value) > self.max_length:
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
def clean(self, value):
value = super(URLField, self).clean(value)
- if not self.required and value == u'':
+ if value == u'':
return value
if self.verify_exists:
import urllib2
@@ -329,9 +328,10 @@ def clean(self, value):
Validates that the input is in self.choices.
"""
value = super(ChoiceField, self).clean(value)
- if value in EMPTY_VALUES: value = u''
+ if value in EMPTY_VALUES:
+ value = u''
value = smart_unicode(value)
- if not self.required and value == u'':
+ if value == u'':
return value
valid_values = set([str(k) for k, v in self.choices])
if value not in valid_values:
Please sign in to comment.
Something went wrong with that request. Please try again.