finding out where a (property) value was acquired from
Is there a way to find out where a value (specifically a property value, but the answer's probably not dependent on that) is acquired from? I have a hierarchy of folders, with some properties set in high-level folders that apply to all the folders below them. Sometimes an action needs to change these values, but they should change in the folder they were acquired from not the current folder. Is there something built-in to Zope that gives me the folder a value (or a property) was acquired from? Or do I simply have to walk the path back towards the root to find it?
Mitchell L Model writes:
Is there something built-in to Zope that gives me the folder a value (or a property) was acquired from? Or do I simply have to walk the path back towards the root to find it? No.
If the object you access is not a property (simple type) but an AcquisitionWrapper, you can use "wrapper.aq_inner.aq_parent" to locate the the containing object (works only in an external method, as "aq_inner" is not considered safe (do not know why!)). For objects of simple type, you would need to emulate the acquisition lookup: External method "findContainer": def findContainer(obj,attr): if hasattr(obj,'aq_self'): c= findContainer(obj.aq_self,attr) if c is None: return findContainer(obj.aq_parent,attr) return c if hasattr(obj,attr): return obj return None This will return either the containing object or None. Dieter
participants (2)
-
Dieter Maurer -
Mitchell L Model