[Zope3-Users] Seeking Explicit Acquisition Support re Climbing Containment Hierarchy

Jeff Rush jeff at taupro.com
Thu Apr 6 03:18:36 EDT 2006


Michael Howitz wrote:
> Am Mittwoch, den 05.04.2006, 09:36 -0500 schrieb Jeff Rush:
> 
>>I know that Zope3 dropped 'implicit' acquisition, but is there any support for 
>>*explicit* acquisition that walks the __parent__ containment hierarchy. 
>>Something that follows the same rules as traverse() to look up a name, but 
>>from bottom-to-top instead of traverse() from top-to-bottom?
> 
> for a project we wrote the following function. It climbes up the
> conatinment hierachy until it finds an object which implements the given
> interface.

<snip function source>

Thanks Michael for the function.  It seems very useful and I'll add it to my 
toolkit.

Jürgen made me aware of the ++acquire++NAME pathing and I've come up with a 
solution using that approach.

I have three levels of containers; ventures, ledgers, entries.

When producing views of ledgers, I wanted to be able to display the venture's 
name, "context/venture/legalname", and when displaying a ledger entry, the 
ledger's description, "context/ledger/desc".

By adding to my venture class,

   def venture(self):
       return self

And to the ledger class,

   def ledger(self):
       return self

I am now able to do things like:

   <span tal:content="context/++acquire++venture/legalname" />
and
   <span tal:content="context/++acquire++/ledger/desc" />

It might be interesting to add your function as a namespace, and do:

   <span tal:content="context/++interface++IVenture/legalname" />

Your approach is more general, not requiring the building in of support for 
"return self" in each container class.

-Jeff


More information about the Zope3-users mailing list