From f529a1f12ea4f96f1d3de1458f77bcfdf4229879 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 4 Apr 2007 13:52:35 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20#3597=20--=20Fixed=20unicode=20encoding?= =?UTF-8?q?=20problem=20in=20form=20rendering.=20Thanks,=20Georgi=20Stanoj?= =?UTF-8?q?evski=20and=20Ville=20S=C3=A4=C3=A4vuori.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@4924 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/newforms/forms.py | 3 ++- tests/regressiontests/forms/regressions.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 9affe2fc82..5d7adfe812 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -5,6 +5,7 @@ Form classes from django.utils.datastructures import SortedDict, MultiValueDict from django.utils.html import escape from django.utils.encoding import StrAndUnicode +from django.conf import settings from fields import Field from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput from util import flatatt, ErrorDict, ErrorList, ValidationError @@ -230,7 +231,7 @@ class BoundField(StrAndUnicode): # Some Widget render() methods -- notably RadioSelect -- return a # "special" object rather than a string. Call the __str__() on that # object to get its rendered value. - value = value.__str__() + value = value.__unicode__() return value def _errors(self): diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py index 02b38ec58d..5daabc03af 100644 --- a/tests/regressiontests/forms/regressions.py +++ b/tests/regressiontests/forms/regressions.py @@ -11,11 +11,11 @@ It should be possible to re-use attribute dictionaries (#3810) >>> TestForm(auto_id=False).as_p() u'

F1:

\n

F2:

' -####################### -# Tests for form i18n # -####################### +####################### +# Tests for form i18n # +####################### There were some problems with form translations in #3600 - + >>> from django.utils.translation import gettext_lazy, activate, deactivate >>> class SomeForm(Form): ... username = CharField(max_length=10, label=gettext_lazy('Username')) @@ -26,4 +26,12 @@ There were some problems with form translations in #3600 >>> print f.as_p()

>>> deactivate() + +Unicode decoding problems... +>>> GENDERS = (('0', u'En tied\xe4'), ('1', u'Mies'), ('2', u'Nainen')) +>>> class SomeForm(Form): +... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect()) +>>> f = SomeForm() +>>> f.as_p() +u'

' """