diff --git a/django/newforms/fields.py b/django/newforms/fields.py index b9a210db8c..970a5185da 100644 --- a/django/newforms/fields.py +++ b/django/newforms/fields.py @@ -359,7 +359,7 @@ class ChoiceField(Field): value = smart_unicode(value) if value == u'': return value - valid_values = set([str(k) for k, v in self.choices]) + valid_values = set([smart_unicode(k) for k, v in self.choices]) if value not in valid_values: raise ValidationError(ugettext(u'Select a valid choice. That choice is not one of the available choices.')) return value diff --git a/django/newforms/forms.py b/django/newforms/forms.py index edd1992cf4..2230057c1d 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -4,7 +4,7 @@ Form classes from django.utils.datastructures import SortedDict, MultiValueDict from django.utils.html import escape -from django.utils.encoding import StrAndUnicode +from django.utils.encoding import StrAndUnicode, smart_unicode from fields import Field from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput from util import flatatt, ErrorDict, ErrorList, ValidationError @@ -311,8 +311,8 @@ class BoundField(StrAndUnicode): associated Form has specified auto_id. Returns an empty string otherwise. """ auto_id = self.form.auto_id - if auto_id and '%s' in str(auto_id): - return str(auto_id) % self.html_name + if auto_id and '%s' in smart_unicode(auto_id): + return smart_unicode(auto_id) % self.html_name elif auto_id: return self.html_name return '' diff --git a/django/newforms/models.py b/django/newforms/models.py index cee6ab1c74..c89cb9cadd 100644 --- a/django/newforms/models.py +++ b/django/newforms/models.py @@ -4,6 +4,7 @@ and database field objects. """ from django.utils.translation import ugettext +from django.utils.encoding import smart_unicode from util import ValidationError from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList from fields import Field, ChoiceField @@ -120,7 +121,7 @@ class QuerySetIterator(object): if self.empty_label is not None: yield (u"", self.empty_label) for obj in self.queryset: - yield (obj._get_pk_val(), str(obj)) + yield (obj._get_pk_val(), smart_unicode(obj)) # Clear the QuerySet cache if required. if not self.cache_choices: self.queryset._result_cache = None diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py index c5a94db6f9..caa0f68741 100644 --- a/tests/regressiontests/forms/regressions.py +++ b/tests/regressiontests/forms/regressions.py @@ -36,4 +36,14 @@ Unicode decoding problems... >>> f = SomeForm() >>> f.as_p() u'