Unicode error in newforms\forms.py
|Reported by:||Owned by:||Malcolm Tredinnick|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When translating a project, I ran into a Unicode error in newforms. As it seems, the field label wasn't being
smart_unicode-d. A small patch is attached to fix that problem.
(Actually, two patches. Fix the same problem, but in different functions. Don't know where you want the problem fixed - but method B is probably better.)
The same problem persists with help_text, although that doesn't seem as easy to fix. If one uses
help_text=gettext("foo") everything works fine (as help_text is thrown through
Field.__init__()). But if one uses
help_text is a
Promise instance, doesn't get encoded and an exception is raised when string formatting is done.
A dirty hack to avoid this could be to call
__str__() directly, that is change [browser:django/trunk/django/newforms/forms.py#5481#L136]
help_text = help_text_html % field.help_text
help_text = help_text_html % smart_unicode(field.help_text.__str__())
.. but this probably doesn't qualify as a fix ;) !!
Or, hmm. Well. Shouldn't field.help_text be escaped at this point anyway? So perhaps the line should be changed to
help_text = help_text_html % smart_unicode(escape(field.help_text))
Better add a third patch with this included..