[Zope-dev] Accessing parent object

Robert Sander zope-dev@beteigeuze.cs.tu-berlin.de
Thu, 24 Feb 2000 14:58:58 +0100


On Thu, Feb 24, 2000 at 07:38:59AM -0600, Evan Simpson wrote:

> > class One(Implicit, Persistent, RoleManager, Folder):
> >     attribute = "Some text or something else"
> >     def somemethod(self):
> >         ob = Two()
> >         self._setObject("id", ob)
> >         ob.method()
> >
> > class Two(Implicit, Persistent, RoleManager, Folder):
> >     def method(self):
> >         print self.aq_acquire("attribute")
> >
> > one = One()
> > one.somemethod()
> >
> > Leads toward an AttributeError because aq_acquire was not found in
> > Two.method()
> 
> I'm afraid this isn't going to improve your opinion of the documentation
> <wink>.  Your Two instance doesn't have aq_acquire because it's not in an
> acquisition wrapper;  It would only get one by being acquired, or by
> adding...
> 
> ob = ob.__of__(self)
> 
> ...before the 'ob.method()' line.

That works now, and it improves my opinion about this mailing list and its 
involved members ;-)

> Searching www.zope.org on Acquisition gets me quite a few documents,
> including Jim Fulton's
> http://www.zope.org/Members/jim/Info/IPC8/AqAlgNews

I found these documents already, but they do not help very much.

> Admittedly, none of them seems to talk about the aq_* methods.  You don't
> have to hit the C source, though; See lib/Components/ExtensionClass/*.stx
> (docs in structured text).

Ah, some docs! ;-) I have them in 
./lib/python/StructuredText/regressions/Acquisition.stx and did not know 
anything about them ...

Now I have my classes subclassed from Acquistion.Implicit, therefore I do not 
need to aq_acquire, which is explicit, I think.

The part where I begin to wonder is my third class:

class Three(Implicit, Persistent, RoleManager, OFS.SimpleItem.Item):
    def method(self):
        print self.aq_acquire("something")

whose objects are children to objects of Two. I do not get AttributeErrors 
here, even if I do not do "three = three.__of__(two)" ...

Greetings
-- 
Robert Sander                                 www.gurubert.de