Opened 18 years ago
Closed 18 years ago
#3996 closed (fixed)
[unicode][patch] NodeList and smart_str prefer __str__ to __unicode__
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Uncategorized | Version: | other branch |
Severity: | Keywords: | unicode | |
Cc: | Maniac@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This is tricky one :-)
When a template is rendered its NodeList does somethig like this:
''.join([smart_str(node, settings.DEFAULT_CHARSET) for node in nodes])
The smart_str converts any object to a str. Now, if an object is a model instance and that only __unicode__ method, smart_str doesn't use it at all and uses instead default Model.__str__. This leads to simple things like this:
{{ obj }}
to give out "ModelName object" instead of meaningful things.
I'm not sure where to fix it:
- change smart_str to look for __unicode__ and call it explicitly before str()
- change NodeList to do
u''.join(...).decode(settings.DEFAULT_CHARSET)
- (not a fix but masking) change Model.__str__ to look into __unicode__
I actually prefer to do all these items, they all seem logical. Except may be the first one since I don't understand completely the semantics of smart_str.
Attachments (1)
Change History (5)
comment:1 by , 18 years ago
Keywords: | unicode added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 18 years ago
Cc: | removed |
---|---|
Owner: | changed from | to
by , 18 years ago
comment:3 by , 18 years ago
Summary: | [unicode] NodeList and smart_str prefer __str__ to __unicode__ → [unicode][patch] NodeList and smart_str prefer __str__ to __unicode__ |
---|
Added a (quite simple) patch. Malcolm, I think I see now why we shouldn't join unicode objects and convert afterwards. This is because you intend to leave users an option to define str for their models instead of unicode. This way we should explicitly use it.
comment:4 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch