Fixed #3597 -- Fixed unicode encoding problem in form rendering. Thanks,

Georgi Stanojevski and Ville Säävuori.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4924 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-04-04 13:52:35 +00:00
parent 56d56e5bac
commit f529a1f12e
2 changed files with 14 additions and 5 deletions

View File

@ -5,6 +5,7 @@ Form classes
from django.utils.datastructures import SortedDict, MultiValueDict from django.utils.datastructures import SortedDict, MultiValueDict
from django.utils.html import escape from django.utils.html import escape
from django.utils.encoding import StrAndUnicode from django.utils.encoding import StrAndUnicode
from django.conf import settings
from fields import Field from fields import Field
from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
from util import flatatt, ErrorDict, ErrorList, ValidationError from util import flatatt, ErrorDict, ErrorList, ValidationError
@ -230,7 +231,7 @@ class BoundField(StrAndUnicode):
# Some Widget render() methods -- notably RadioSelect -- return a # Some Widget render() methods -- notably RadioSelect -- return a
# "special" object rather than a string. Call the __str__() on that # "special" object rather than a string. Call the __str__() on that
# object to get its rendered value. # object to get its rendered value.
value = value.__str__() value = value.__unicode__()
return value return value
def _errors(self): def _errors(self):

View File

@ -11,11 +11,11 @@ It should be possible to re-use attribute dictionaries (#3810)
>>> TestForm(auto_id=False).as_p() >>> TestForm(auto_id=False).as_p()
u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>' u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>'
####################### #######################
# Tests for form i18n # # Tests for form i18n #
####################### #######################
There were some problems with form translations in #3600 There were some problems with form translations in #3600
>>> from django.utils.translation import gettext_lazy, activate, deactivate >>> from django.utils.translation import gettext_lazy, activate, deactivate
>>> class SomeForm(Form): >>> class SomeForm(Form):
... username = CharField(max_length=10, label=gettext_lazy('Username')) ... 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() >>> print f.as_p()
<p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p> <p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
>>> deactivate() >>> 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'<p><label for="id_somechoice_0">Somechoice:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="0" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="1" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="2" name="somechoice" /> Nainen</label></li>\n</ul></p>'
""" """