[Zope] aquisition+init problem

Casey Duncan cduncan@kaivo.com
Wed, 18 Jul 2001 08:35:09 -0600


Koukis Dimitrios-Vassilios wrote:
> 
> I am facing a problem while tring to develop a product.I want to use an
> attribute of the parent of my object but the problem is that i want to use
> it in the __init__ method.The problem occurs due to the fact that i am
> tring to use aquisition over the object while it is not "ready" because
> __init__ isn't over yet.(for example there is no attribute self.aq_parent
> meaning that aquisition can't be used yet ).
> In particular i have a folder containing a database connection and in
> the same folder i am tring to create an instance of my object.In it's
> __init__  method i want to contact the database and create a table for
> example.The problem is that the database connection can't be found because
> as said before there is no aquisition yet.
> So if i want to do something while constructing the object using a function
> that requires an attribute of the parent what should i do?
>                                                         Thanx
> 
> PS:Because i am not yet subscribed to the list please be sure that my
> e-mail address is in the cc field.A
> 

You must pass the container to __init__ and create a wrapper manually,
like so:

def __init__(self, container):
   wrapped = self.__of__(container)
   wrapped.some_acquired_attr...

There are several examples of this in the Zope source. I think
Catalog.py (in the ZCatalog product) is such a beast, it needs to
acquire a vocabulary when it is instantiated.

hth,
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>