- Description:
-
Handle unicode/str cast operators.
A few of our objects defined
__str__and/or__unicode__methods. This presentssome complications for porting to python 3, since str has different meanings. Django provides a decorator,
@python_2_unicode_compatible, whereby you define__str__using python 3 semantics (i.e. it returns unicode), and when runningwith python 2, it will rename that to __unicode__and make__str__call thatand encode to utf-8. - - Confusingly, for a couple of our models (specifically Group and Screenshot),
- using this decorator would drop into an infinite recursion of __unicode__ - lambdas. I really don't know why this was happening, but using the StrToUnicode - mixin works. The only unfortunate thing is that StrToUnicode uses the python 2 - semantics (defining __unicode__) instead of 3 (__str__). - Diff:
-
Revision 2 (+56 -27)
Handle unicode/str cast operators.
Review Request #4920 — Created Nov. 8, 2013 and submitted
Handle unicode/str cast operators.
A few of our objects defined
__str__and/or__unicode__methods. This presents
some complications for porting to python 3, since str has different meanings.Django provides a decorator,
@python_2_unicode_compatible, whereby you define
__str__using python 3 semantics (i.e. it returns unicode), and when running
with python 2, it will rename that to__unicode__and make__str__call that
and encode to utf-8.
- Ran unit tests
- Checked list displays in the admin