[Zope-dev] Accessing parent object

Robert Sander zope-dev@beteigeuze.cs.tu-berlin.de
Fri, 18 Feb 2000 15:08:16 +0100


Hi!

OK, I learned that I can use self.aq_parent to get the parent object of self.

I defined the following:

from Acquisition import Implicit
from AccessControl.Role import RoleManager
from OFS.Folder import Folder
from OFS.SimpleItem import Item
from Globals import Persistent

class One(Folder, Persistent, Implicit, RoleManager):
    def uno(self):
        return self
    attribute = "some text for example"

class Two(Folder, Persistent, Implicit, RoleManager):
    def uno(self):
        return self.aq_parent.uno()

class Three(Implicit, Persistent, RoleManager, Item):
    def uno(self):
        return self.aq_parent.uno()

    def output(self):
        print self.uno().attribute

If I have a treelike-structure I should now be able to access my "toplevel" 
object which is of the class One from any objects of the class Three that are 
contained in objects of class Two, which are contained in an object of class 
One.

But the call to Two.uno() raises an AttributeError, aq_parent is not know. In 
objects of class Three self.aq_parent raises no error. Is the Folder class the 
problem here? This is the only difference between Three and Two.

Any help is appreciated.

Greetings
-- 
Robert Sander                                 www.gurubert.de