[Zope] How can a method know if it was acquired?
Stuart Bishop
zen@shangri-la.dropbear.id.au
Tue, 8 Jul 2003 16:15:34 +1000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Monday, July 7, 2003, at 08:00 PM, Itai Tavor wrote:
> I got a folderish python product with the following method:
>
> def SKU(self):
> """ Return our SKU for the catalog """
> return self.sku
>
> The problem is that when objects contained in instances of this
> product are cataloged, they acquire the SKU method, so they also get
> the sku property. That is bad. So what I need is something like this:
>
> def SKU(self):
> """ Return our SKU for the catalog """
> if (I was acquired):
> return None
> else:
> return self.sku
>
> But I can't figure out how to do that. Help?
Try this:
from Aquisition import aq_explicit
[...]
def SKU(self):
'return SKU if we really have one, and not just aquired one'
try:
return aq_explicit(self).sku
except AttributeError:
return None
or...
def SKU(self)
'return SKU if we really have one'
if hasattr(aq_explicit(self),'SKU'):
return self.sky
else:
return None
You can also catalog the meta_type of the object, and use that in the
query.
- --
Stuart Bishop <zen@shangri-la.dropbear.id.au>
http://shangri-la.dropbear.id.au/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (Darwin)
iD8DBQE/CmGHh8iUz1x5geARAlkpAKDyCx9h13/+/Dxzh13fwm+/H+6+zQCggC86
GkhQC5xCIjZcTZp/hue4dZo=
=1UvW
-----END PGP SIGNATURE-----