[Zope-Coders] SimpleItem.getId busted
Stuart Bishop
stuart at stuartbishop.net
Thu Nov 20 00:42:11 EST 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I'd like to change:
def getId(self):
"""Return the id of the object as a string. This method
should be used in preference to accessing an id attribute
of an object directly. The getId method is public."""
name=getattr(self, 'id', None)
if callable(name):
return name()
if name is not None:
return name
if hasattr(self, '__name__'):
return self.__name__
raise AttributeError, 'This object has no id'
to:
def getId(self):
"""Return the id of the object as a string. This method
should be used in preference to accessing an id attribute
of an object directly. The getId method is public."""
name = getattr(aq_base(self), 'id', None)
if callable(name):
return name()
if name:
return name
try:
return self.__name__
except AttributeError:
raise AttributeError, 'This object has no id'
This makes the getId() method actually work for PageTemplateFile's,
and all the methods that rely on it like absolute_url().
It is sort-of backward compatible, as people doing
string:${template/absolute_url}/myid to work around this bug will
still get valid links thanks to aquisition, but it aint pretty.
Any objections to me fixing the HEAD?
What branches should this be back ported to? This goes back to at least
2.6 and possibly further to when __name__ was first introduced.
- --
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)
iD8DBQE/vFQ3AfqZj7rGN0oRAubqAKCGooZRzMJ13DpeiW7WKSo0ezYwFACfZkyu
w2Efjlt1gqt/K6DB7l4kqY4=
=T0cB
-----END PGP SIGNATURE-----
More information about the Zope-Coders
mailing list