Fixed #4804 -- Fixed a problem when validating choice lists with non-ASCII

data. Thanks, django@vonposer.de.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5642 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-07-10 12:03:36 +00:00
parent cc1a4f031c
commit 87d8976fae
2 changed files with 3 additions and 3 deletions

View File

@ -3,7 +3,7 @@ from django.core.exceptions import PermissionDenied
from django.utils.html import escape from django.utils.html import escape
from django.conf import settings from django.conf import settings
from django.utils.translation import ugettext, ungettext from django.utils.translation import ugettext, ungettext
from django.utils.encoding import smart_unicode, force_unicode, smart_str from django.utils.encoding import smart_unicode, force_unicode
FORM_FIELD_ID_PREFIX = 'id_' FORM_FIELD_ID_PREFIX = 'id_'
@ -502,7 +502,7 @@ class SelectField(FormField):
def isValidChoice(self, data, form): def isValidChoice(self, data, form):
str_data = smart_unicode(data) str_data = smart_unicode(data)
str_choices = [smart_str(item[0]) for item in self.choices] str_choices = [smart_unicode(item[0]) for item in self.choices]
if str_data not in str_choices: if str_data not in str_choices:
raise validators.ValidationError, ugettext("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data': str_data, 'choices': str_choices} raise validators.ValidationError, ugettext("Select a valid choice; '%(data)s' is not in %(choices)s.") % {'data': str_data, 'choices': str_choices}

View File

@ -54,7 +54,7 @@ True
# Attempt to create an Album with an invalid musician. # Attempt to create an Album with an invalid musician.
>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']})) >>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']}))
{'musician': [u"Select a valid choice; 'foo' is not in ['', '1']."]} {'musician': [u"Select a valid choice; 'foo' is not in [u'', u'1']."]}
# Attempt to create an Album with an invalid release_date. # Attempt to create an Album with an invalid release_date.
>>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['1'], 'release_date': 'today'})) >>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['1'], 'release_date': 'today'}))