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

Dieter Maurer dieter@handshake.de
Wed, 15 Aug 2001 21:29:51 +0200 (CEST)


Martijn Jacobs writes:
I redirected my reply to "zope.org"....

 > I have a question about acquisition and namespaces and how to use them in
 > your product code.....
 > ....
 > Root
 >  |
 >  ----ProductA
 >                                         ----ProductB
 >                                         |
 >                                         ----DTMLDoc1
 > 
 > 
 > OK : If I execute http://localhost/ProductA/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,
It will *NOT* call the "index_html" from "dtml-var"!
This will happen only when the object is activated from ZPublisher.

 > because in DTML you have a namespace where the DTML-execute code can
 > find 'ProductA' on a great way.
That's not the reason. See below...

 > 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'  ?
In DTML, you have two orthogonal lookup facilities: acquisition
and the DTML namespace. When you are in your "DTMLDoc1",
the namespace is only weakly used to find "ProductA".
The primary work is done by acquisition.

Unless you are in a class constructor, you can also rely on
acquisition inside a product (when it subclasses "Acquisition.Implicit").
For example in a "ProductB" instance, you could
use "self.ProductA" to access the "ProductA" instance depicted
in your folder structure.

More info

  URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html




Dieter