Opened 17 years ago
Closed 17 years ago
#4593 closed (wontfix)
Unicode error in newforms\forms.py
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Keywords: | unicode newforms | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 smart_unicode
in newform\fields.py
's Field.__init__()
). But if one uses gettext_lazy
, 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 help_text
's __str__()
directly, that is change [browser:django/trunk/django/newforms/forms.py#5481#L136]
help_text = help_text_html % field.help_text
to
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..
Attachments (3)
Change History (4)
by , 17 years ago
Attachment: | unicode.newforms.a.patch added |
---|
by , 17 years ago
Attachment: | unicode.newforms.b.patch added |
---|
Encode label in label_tag using smart_unicode
by , 17 years ago
Attachment: | unicode.newforms.c.patch added |
---|
Encode label in label_tag and help_text in _html_output using smart_unicode
comment:1 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Thanks for the patch. However, this is the type of problem we've fixed right across the unicode branch (in a slightly different fashion). So we aren't going to be fixing isolated incidents on trunk, but rather moving towards merging the unicode branch into trunk as soon as possible.
Encode label in _html_output using smart_unicode