1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

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
This commit is contained in:
Malcolm Tredinnick 2007-05-28 13:02:16 +00:00
parent 7bb9a8e3ae
commit 4d31b5297b
3 changed files with 13 additions and 6 deletions

View File

@ -136,7 +136,7 @@ class BaseForm(StrAndUnicode):
help_text = help_text_html % force_unicode(field.help_text) help_text = help_text_html % force_unicode(field.help_text)
else: else:
help_text = u'' help_text = u''
output.append(normal_row % {'errors': bf_errors, 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text}) output.append(normal_row % {'errors': force_unicode(bf_errors), 'label': force_unicode(label), 'field': unicode(bf), 'help_text': help_text})
if top_errors: if top_errors:
output.insert(0, error_row % top_errors) output.insert(0, error_row % top_errors)
if hidden_fields: # Insert any hidden fields in the last row. if hidden_fields: # Insert any hidden fields in the last row.

View File

@ -1,5 +1,5 @@
from django.utils.html import escape from django.utils.html import escape
from django.utils.encoding import smart_unicode from django.utils.encoding import smart_unicode, StrAndUnicode
def flatatt(attrs): def flatatt(attrs):
""" """
@ -10,13 +10,13 @@ def flatatt(attrs):
""" """
return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()]) return u''.join([u' %s="%s"' % (k, escape(v)) for k, v in attrs.items()])
class ErrorDict(dict): class ErrorDict(dict, StrAndUnicode):
""" """
A collection of errors that knows how to display itself in various formats. A collection of errors that knows how to display itself in various formats.
The dictionary keys are the field names, and the values are the errors. The dictionary keys are the field names, and the values are the errors.
""" """
def __str__(self): def __unicode__(self):
return self.as_ul() return self.as_ul()
def as_ul(self): def as_ul(self):
@ -26,11 +26,11 @@ class ErrorDict(dict):
def as_text(self): def as_text(self):
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()]) 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()])
class ErrorList(list): class ErrorList(list, StrAndUnicode):
""" """
A collection of errors that knows how to display itself in various formats. A collection of errors that knows how to display itself in various formats.
""" """
def __str__(self): def __unicode__(self):
return self.as_ul() return self.as_ul()
def as_ul(self): def as_ul(self):

View File

@ -53,6 +53,13 @@ u'\u0448\u0442.'
>>> f.clean('\xd1\x88\xd1\x82.') >>> f.clean('\xd1\x88\xd1\x82.')
u'\u0448\u0442.' u'\u0448\u0442.'
Translated error messages used to be buggy.
>>> activate('ru')
>>> f = SomeForm({})
>>> f.as_p()
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>'
>>> deactivate()
####################### #######################
# Miscellaneous Tests # # Miscellaneous Tests #
####################### #######################