mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes. Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -16,24 +16,63 @@ u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>
|
||||
#######################
|
||||
There were some problems with form translations in #3600
|
||||
|
||||
>>> from django.utils.translation import gettext_lazy, activate, deactivate
|
||||
>>> from django.utils.translation import ugettext_lazy, activate, deactivate
|
||||
>>> class SomeForm(Form):
|
||||
... username = CharField(max_length=10, label=gettext_lazy('Username'))
|
||||
... username = CharField(max_length=10, label=ugettext_lazy('Username'))
|
||||
>>> f = SomeForm()
|
||||
>>> print f.as_p()
|
||||
<p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
|
||||
|
||||
Translations are done at rendering time, so multi-lingual apps can define forms
|
||||
early and still send back the right translation.
|
||||
|
||||
# XFAIL
|
||||
>>> activate('de')
|
||||
>>> print f.as_p()
|
||||
<p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
|
||||
>>> activate('pl')
|
||||
>>> f.as_p()
|
||||
u'<p><label for="id_username">Nazwa u\u017cytkownika:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>'
|
||||
>>> deactivate()
|
||||
|
||||
Unicode decoding problems...
|
||||
>>> GENDERS = (('0', u'En tied\xe4'), ('1', u'Mies'), ('2', u'Nainen'))
|
||||
>>> GENDERS = ((u'\xc5', u'En tied\xe4'), (u'\xf8', u'Mies'), (u'\xdf', u'Nainen'))
|
||||
>>> class SomeForm(Form):
|
||||
... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect())
|
||||
... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect(), label=u'\xc5\xf8\xdf')
|
||||
>>> 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>'
|
||||
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>'
|
||||
|
||||
Testing choice validation with UTF-8 bytestrings as input (these are the
|
||||
Russian abbreviations "мес." and "шт.".
|
||||
|
||||
>>> UNITS = (('\xd0\xbc\xd0\xb5\xd1\x81.', '\xd0\xbc\xd0\xb5\xd1\x81.'), ('\xd1\x88\xd1\x82.', '\xd1\x88\xd1\x82.'))
|
||||
>>> f = ChoiceField(choices=UNITS)
|
||||
>>> f.clean(u'\u0448\u0442.')
|
||||
u'\u0448\u0442.'
|
||||
>>> f.clean('\xd1\x88\xd1\x82.')
|
||||
u'\u0448\u0442.'
|
||||
|
||||
Translated error messages used to be buggy.
|
||||
>>> activate('ru')
|
||||
>>> f = SomeForm({})
|
||||
>>> f.as_p()
|
||||
u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<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>'
|
||||
>>> deactivate()
|
||||
|
||||
#######################
|
||||
# Miscellaneous Tests #
|
||||
#######################
|
||||
|
||||
There once was a problem with Form fields called "data". Let's make sure that
|
||||
doesn't come back.
|
||||
>>> class DataForm(Form):
|
||||
... data = CharField(max_length=10)
|
||||
>>> f = DataForm({'data': 'xyzzy'})
|
||||
>>> f.is_valid()
|
||||
True
|
||||
>>> f.cleaned_data
|
||||
{'data': u'xyzzy'}
|
||||
|
||||
#######################
|
||||
# Miscellaneous Tests #
|
||||
|
||||
Reference in New Issue
Block a user