[Zope-dev] Finding specific parent object with acquisition ?

Martijn Pieters mj@zope.com
Wed, 15 Aug 2001 12:34:10 -0400


> I have a question about acquisition and namespaces and how to use them in
> your product code.....
>
> Imagine you have the following structure in zope :
> (ProductA is a Product derived from Folder/Objectmanager so it can hold
other
> objects, ProductB is a simpleitem product)
>
> Root
>  |
>   ----ProductA
>                |
>                ----Folder6
>                            |
>                            ----Folder7
>                                         |
>                                         ----ProductB
>                                         |
>                                         ----DTMLDoc1
>
>
> OK : If I execute http://localhost/ProductA/Folder6/Folder7/DTMLDoc1 and I
> put in the DTMLDoc1 this code :  '<dtml-var "ProductA">' , it will look
> back and it will find the ProductA instance and it will call it's
index_html,
> because in DTML you have a namespace where the DTML-execute code can
> find 'ProductA' on a great way.
>
> Now the following thing : I want to acquire a reference TO ProductA
> IN the product code of ProductB so I will be able to execute functions
from
> ProductA in ProductB, for example :
>
> class ProductB(.....)
>    def blah():
>       refProdA = self.acquire('ProductA');
>
> (self.acquire is not a real function, only for illustration what kind of
>  function I would like to have in a Zope object :)
>
> Do I have a same namespace in my Productcode (the python code of this
product)
> so it will acquire automaticily the reference to ProductA, for example the
way
> I use here above?  Or do I have to program this manually by repeatly
calling
> the aq_parent method until I find an instance of 'ProductA'  ?

You can simply refer to self.ProductA if you inherit from SimpleItem (it
includes implicit acquisition). You can also acquire the REQUEST object that
way, for instance.

PS. Cool, 'nother Martijn. Remeber, Martijn Faassen is The Other Martijn
(even if he claims I am), I'm The Original Martijn. Not sure what we'll call
you though... This has nothing to do with the Dutch conspiracy, as it
doesn't exist.

Nice to see another Dutch Web agency use Zope for Content Management. I
never was able to convince my previous employer of the advantages, as
"everyone wants Java"..

--
Martijn Pieters
| Software Engineer  mailto:mj@zope.com
| Zope Corporation   http://www.zope.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------