Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit f529a1f12ea4f96f1d3de1458f77bcfdf4229879 1 parent 56d56e5
Malcolm Tredinnick authored April 04, 2007
3  django/newforms/forms.py
@@ -5,6 +5,7 @@
5 5
 from django.utils.datastructures import SortedDict, MultiValueDict
6 6
 from django.utils.html import escape
7 7
 from django.utils.encoding import StrAndUnicode
  8
+from django.conf import settings
8 9
 from fields import Field
9 10
 from widgets import TextInput, Textarea, HiddenInput, MultipleHiddenInput
10 11
 from util import flatatt, ErrorDict, ErrorList, ValidationError
@@ -230,7 +231,7 @@ def __unicode__(self):
230 231
             # Some Widget render() methods -- notably RadioSelect -- return a
231 232
             # "special" object rather than a string. Call the __str__() on that
232 233
             # object to get its rendered value.
233  
-            value = value.__str__()
  234
+            value = value.__unicode__()
234 235
         return value
235 236
 
236 237
     def _errors(self):
16  tests/regressiontests/forms/regressions.py
@@ -11,11 +11,11 @@
11 11
 >>> TestForm(auto_id=False).as_p()
12 12
 u'<p>F1: <input type="text" class="special" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" class="special" name="f2" /></p>'
13 13
 
14  
-####################### 
15  
-# Tests for form i18n # 
16  
-####################### 
  14
+#######################
  15
+# Tests for form i18n #
  16
+#######################
17 17
 There were some problems with form translations in #3600
18  
- 
  18
+
19 19
 >>> from django.utils.translation import gettext_lazy, activate, deactivate
20 20
 >>> class SomeForm(Form):
21 21
 ...     username = CharField(max_length=10, label=gettext_lazy('Username'))
@@ -26,4 +26,12 @@
26 26
 >>> print f.as_p()
27 27
 <p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>
28 28
 >>> deactivate()
  29
+
  30
+Unicode decoding problems...
  31
+>>> GENDERS = (('0', u'En tied\xe4'), ('1', u'Mies'), ('2', u'Nainen'))
  32
+>>> class SomeForm(Form):
  33
+...     somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect())
  34
+>>> f = SomeForm()
  35
+>>> f.as_p()
  36
+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>'
29 37
 """

0 notes on commit f529a1f

Please sign in to comment.
Something went wrong with that request. Please try again.