summaryrefslogtreecommitdiff
path: root/django/newforms/fields.py
diff options
context:
space:
mode:
authorBoulder Sprinters <boulder-sprinters@djangoproject.com>2006-11-17 06:47:43 +0000
committerBoulder Sprinters <boulder-sprinters@djangoproject.com>2006-11-17 06:47:43 +0000
commit8154294a0fb0134a13676642d13e525901d6bc97 (patch)
treee7d3331b6a0cbb17af0e989de685887f8069bfa0 /django/newforms/fields.py
parent1b0d6b942c39bf0f5105be2d47e6e844e43a2659 (diff)
boulder-oracle-sprint: Merged to [4077] of trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4083 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/newforms/fields.py')
-rw-r--r--django/newforms/fields.py24
1 files changed, 6 insertions, 18 deletions
diff --git a/django/newforms/fields.py b/django/newforms/fields.py
index b9e2ed35c7..179555fc77 100644
--- a/django/newforms/fields.py
+++ b/django/newforms/fields.py
@@ -2,7 +2,7 @@
Field classes
"""
-from util import ValidationError, DEFAULT_ENCODING
+from util import ValidationError, DEFAULT_ENCODING, smart_unicode
from widgets import TextInput, CheckboxInput, Select, SelectMultiple
import datetime
import re
@@ -55,10 +55,7 @@ class CharField(Field):
"Validates max_length and min_length. Returns a Unicode object."
Field.clean(self, value)
if value in EMPTY_VALUES: value = u''
- if not isinstance(value, basestring):
- value = unicode(str(value), DEFAULT_ENCODING)
- elif not isinstance(value, unicode):
- value = unicode(value, DEFAULT_ENCODING)
+ value = smart_unicode(value)
if self.max_length is not None and len(value) > self.max_length:
raise ValidationError(u'Ensure this value has at most %d characters.' % self.max_length)
if self.min_length is not None and len(value) < self.min_length:
@@ -165,10 +162,7 @@ class RegexField(Field):
"""
Field.clean(self, value)
if value in EMPTY_VALUES: value = u''
- if not isinstance(value, basestring):
- value = unicode(str(value), DEFAULT_ENCODING)
- elif not isinstance(value, unicode):
- value = unicode(value, DEFAULT_ENCODING)
+ value = smart_unicode(value)
if not self.regex.search(value):
raise ValidationError(self.error_message)
return value
@@ -244,10 +238,7 @@ class ChoiceField(Field):
"""
value = Field.clean(self, value)
if value in EMPTY_VALUES: value = u''
- if not isinstance(value, basestring):
- value = unicode(str(value), DEFAULT_ENCODING)
- elif not isinstance(value, unicode):
- value = unicode(value, DEFAULT_ENCODING)
+ value = smart_unicode(value)
valid_values = set([str(k) for k, v in self.choices])
if value not in valid_values:
raise ValidationError(u'Select a valid choice. %s is not one of the available choices.' % value)
@@ -267,11 +258,8 @@ class MultipleChoiceField(ChoiceField):
raise ValidationError(u'This field is required.')
new_value = []
for val in value:
- if not isinstance(val, basestring):
- value = unicode(str(val), DEFAULT_ENCODING)
- elif not isinstance(val, unicode):
- value = unicode(val, DEFAULT_ENCODING)
- new_value.append(value)
+ val = smart_unicode(val)
+ new_value.append(val)
# Validate that each value in the value list is in self.choices.
valid_values = set([k for k, v in self.choices])
for val in new_value: