From 4d31b5297bc7866febdbc4a0875878202c6bacd0 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 28 May 2007 13:02:16 +0000 Subject: [PATCH] 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 --- django/newforms/forms.py | 2 +- django/newforms/util.py | 10 +++++----- tests/regressiontests/forms/regressions.py | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 67296cf284..649c015d72 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -136,7 +136,7 @@ class BaseForm(StrAndUnicode): help_text = help_text_html % force_unicode(field.help_text) else: 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: output.insert(0, error_row % top_errors) if hidden_fields: # Insert any hidden fields in the last row. diff --git a/django/newforms/util.py b/django/newforms/util.py index 37fe841b61..2bafc8d9c7 100644 --- a/django/newforms/util.py +++ b/django/newforms/util.py @@ -1,5 +1,5 @@ from django.utils.html import escape -from django.utils.encoding import smart_unicode +from django.utils.encoding import smart_unicode, StrAndUnicode 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()]) -class ErrorDict(dict): +class ErrorDict(dict, StrAndUnicode): """ 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. """ - def __str__(self): + def __unicode__(self): return self.as_ul() def as_ul(self): @@ -26,11 +26,11 @@ class ErrorDict(dict): 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()]) -class ErrorList(list): +class ErrorList(list, StrAndUnicode): """ A collection of errors that knows how to display itself in various formats. """ - def __str__(self): + def __unicode__(self): return self.as_ul() def as_ul(self): diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py index 723cad53cd..54b9138b20 100644 --- a/tests/regressiontests/forms/regressions.py +++ b/tests/regressiontests/forms/regressions.py @@ -53,6 +53,13 @@ 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'

\n

' +>>> deactivate() + ####################### # Miscellaneous Tests # #######################