mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
newforms: Fixed #3008 -- Widgets now support strings containing utf-8 characters. Thanks for reporting, Nebojša Đorđević
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4076 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user