[ZPT] Coerce result using unicode() rather than str() ?
Stuart Bishop
stuart at stuartbishop.net
Thu Jul 1 15:43:47 EDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have an object that defines the __unicode__ method to return
a Unicode representation of the object.
The TALES to get it included in a page template is pretty ugly however:
<span tal:content="python:unicode(m)" />
Of course, I'd much rather just do <span tal:content="m" />
Does it seem like a sane change to render the result as a Unicode
string if the object defines the conversion routine?
if not isinstance(result, (str, unicode)):
if hasattr(result, '__unicode__'):
return unicode(result)
else:
return str(result)
(Hmm... would this be in ZPT or ZPublisher?)
- --
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQFA5Gl6AfqZj7rGN0oRAmWCAJ9UXHxpZSsdX06gsnJgnNOFpMXH9gCffBgW
zwKhK0IDVT37+y5imXjHU4g=
=sPkl
-----END PGP SIGNATURE-----
More information about the ZPT
mailing list