Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #4403 -- Stopped pushing form error messages (which are unicode…

… strings)

through a __str__ method.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5375 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4d31b5297bc7866febdbc4a0875878202c6bacd0 1 parent 7bb9a8e
Malcolm Tredinnick authored May 28, 2007
2  django/newforms/forms.py
@@ -136,7 +136,7 @@ def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_
136 136
                     help_text = help_text_html % force_unicode(field.help_text)
137 137
                 else:
138 138
                     help_text = u''
139  
-                output.append(normal_row % {'errors': bf_errors, 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text})
  139
+                output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text})
140 140
         if top_errors:
141 141
             output.insert(0, error_row % top_errors)
142 142
         if hidden_fields: # Insert any hidden fields in the last row.
10  django/newforms/util.py
... ...
@@ -1,5 +1,5 @@
1 1
 from django.utils.html import escape
2  
-from django.utils.encoding import smart_unicode
  2
+from django.utils.encoding import smart_unicode, StrAndUnicode
3 3
 
4 4
 def flatatt(attrs):
5 5
     """
@@ -10,13 +10,13 @@ def flatatt(attrs):
10 10
     """
11 11
     return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
12 12
 
13  
-class ErrorDict(dict):
  13
+class ErrorDict(dict, StrAndUnicode):
14 14
     """
15 15
     A collection of errors that knows how to display itself in various formats.
16 16
 
17 17
     The dictionary keys are the field names, and the values are the errors.
18 18
     """
19  
-    def __str__(self):
  19
+    def __unicode__(self):
20 20
         return self.as_ul()
21 21
 
22 22
     def as_ul(self):
@@ -26,11 +26,11 @@ def as_ul(self):
26 26
     def as_text(self):
27 27
         return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % smart_unicode(i) for i in v])) for k, v in self.items()])
28 28
 
29  
-class ErrorList(list):
  29
+class ErrorList(list, StrAndUnicode):
30 30
     """
31 31
     A collection of errors that knows how to display itself in various formats.
32 32
     """
33  
-    def __str__(self):
  33
+    def __unicode__(self):
34 34
         return self.as_ul()
35 35
 
36 36
     def as_ul(self):
7  tests/regressiontests/forms/regressions.py
@@ -53,6 +53,13 @@
53 53
 >>> f.clean('\xd1\x88\xd1\x82.')
54 54
 u'\u0448\u0442.'
55 55
 
  56
+Translated error messages used to be buggy.
  57
+>>> activate('ru')
  58
+>>> f = SomeForm({})
  59
+>>> f.as_p()
  60
+u'<p><ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul></p>\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>'
  61
+>>> deactivate()
  62
+
56 63
 #######################
57 64
 # Miscellaneous Tests #
58 65
 #######################

0 notes on commit 4d31b52

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