From 24bacb19dea298943f54155f911df380c73f9ea2 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 31 Aug 2008 11:39:06 +0000 Subject: [PATCH] Fixed #5216 -- Fixed a case of a string not being a unicode string. Thanks to Vadim Fint for the test case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8761 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/forms.py | 2 +- tests/regressiontests/forms/regressions.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/django/forms/forms.py b/django/forms/forms.py index 753ee254bc..7d1254c5ea 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -374,7 +374,7 @@ class BoundField(StrAndUnicode): id_ = widget.attrs.get('id') or self.auto_id if id_: attrs = attrs and flatatt(attrs) or '' - contents = '' % (widget.id_for_label(id_), attrs, contents) + contents = u'' % (widget.id_for_label(id_), attrs, unicode(contents)) return mark_safe(contents) def _is_hidden(self): diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py index 87390d3cd1..5e32cd397d 100644 --- a/tests/regressiontests/forms/regressions.py +++ b/tests/regressiontests/forms/regressions.py @@ -34,6 +34,16 @@ early and still send back the right translation. u'

' >>> deactivate() +There was some problems with form translations in #5216 +>>> class SomeForm(Form): +... field_1 = CharField(max_length=10, label=ugettext_lazy('field_1')) +... field_2 = CharField(max_length=10, label=ugettext_lazy('field_2'), widget=TextInput(attrs={'id': 'field_2_id'})) +>>> f = SomeForm() +>>> print f['field_1'].label_tag() + +>>> print f['field_2'].label_tag() + + Unicode decoding problems... >>> GENDERS = ((u'\xc5', u'En tied\xe4'), (u'\xf8', u'Mies'), (u'\xdf', u'Nainen')) >>> class SomeForm(Form):