Changeset 5236
- Timestamp:
- 05/14/07 11:06:27 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode/django/newforms/fields.py
r5126 r5236 360 360 if value == u'': 361 361 return value 362 valid_values = set([s tr(k) for k, v in self.choices])362 valid_values = set([smart_unicode(k) for k, v in self.choices]) 363 363 if value not in valid_values: 364 364 raise ValidationError(ugettext(u'Select a valid choice. That choice is not one of the available choices.')) django/branches/unicode/django/newforms/forms.py
r5214 r5236 5 5 from django.utils.datastructures import SortedDict, MultiValueDict 6 6 from django.utils.html import escape 7 from django.utils.encoding import StrAndUnicode 7 from django.utils.encoding import StrAndUnicode, smart_unicode 8 8 from fields import Field 9 9 from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput … … 312 312 """ 313 313 auto_id = self.form.auto_id 314 if auto_id and '%s' in s tr(auto_id):315 return s tr(auto_id) % self.html_name314 if auto_id and '%s' in smart_unicode(auto_id): 315 return smart_unicode(auto_id) % self.html_name 316 316 elif auto_id: 317 317 return self.html_name django/branches/unicode/django/newforms/models.py
r5229 r5236 5 5 6 6 from django.utils.translation import ugettext 7 from django.utils.encoding import smart_unicode 7 8 from util import ValidationError 8 9 from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList … … 121 122 yield (u"", self.empty_label) 122 123 for obj in self.queryset: 123 yield (obj._get_pk_val(), s tr(obj))124 yield (obj._get_pk_val(), smart_unicode(obj)) 124 125 # Clear the QuerySet cache if required. 125 126 if not self.cache_choices: django/branches/unicode/tests/regressiontests/forms/regressions.py
r5229 r5236 37 37 >>> f.as_p() 38 38 u'<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>' 39 40 Testing choice validation with UTF-8 bytestrings as input (these are the 41 Russian abbreviations "мес." and "шт.". 42 43 >>> UNITS = (('\xd0\xbc\xd0\xb5\xd1\x81.', '\xd0\xbc\xd0\xb5\xd1\x81.'), ('\xd1\x88\xd1\x82.', '\xd1\x88\xd1\x82.')) 44 >>> f = ChoiceField(choices=UNITS) 45 >>> f.clean(u'\u0448\u0442.') 46 u'\u0448\u0442.' 47 >>> f.clean('\xd1\x88\xd1\x82.') 48 u'\u0448\u0442.' 39 49 """
