Can't use aq_parent in Product??
I have a Product I'm creating (python, not Zclass). I thought that I could get the parent object of an instance of my product using the aq_parent method. But AFAIKT, this only works on an "acquisition wrapper" of an object - not on the object itself?? Example: try this in Boring product: class BrokenBoring( OFS.SimpleItem.Item, # A simple Principia object. Not Folderish. Persistent, # Make us persistent. Yaah! Acquisition.Implicit, # Be able to find things via acquisition. AccessControl.Role.RoleManager # Security manager. ): """ Can't acquire the parent... fooey. """ meta_type = 'Boring' # what do people think they're adding? (snip) def __init__(self, id, title=''): """initialise a new instance of Boring""" (snip) try: assert hasattr(self, "aq_parent") except: print "Hey! This instance can't acquire parent!!" When you add one of these in a folder, it prints the exception message in the log. In other words ... no aq_parent. So I guess I need to get an acquisition wrapper to self, so I can acquire its parent? How do I do that? I can't figure it out from the DevGuide. Or Is there a less bletcherous solution? Help! -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
On Sun, Nov 11, 2001 at 09:05:41PM -0500, Paul Winkler wrote: (snip)
So I guess I need to get an acquisition wrapper to self, so I can acquire its parent? How do I do that? I can't figure it out from the DevGuide. Or Is there a less bletcherous solution?
I figured it out... the solution is right there in the DevGuide, though it doesn't have exactly this example: def __init__(...): ... aqwrapper = self.__of__(self) parent = aqwrapper.aq_parent Now parent is the parent folder of self. Cool. Of course I immediately realized that I don't need this solution at all. {:-l I wanted to conditionally create another object in the parent folder during __init__(), but it finally dawned on me that the easy way to do that is to do it during the manage_addMyProduct() call, in which the *folder* is already available as "self". Duh. Much easier. And it works. -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
In __init__ you are in a pure python class constructor. The object you're constructing has not yet been assigned its place in the Zope tree, so it doesn't *have* a parent. If you want to do post-constructor initializations, do them after the object has been created and put in the tree via _setObject. See my other recent post about this. Florent Paul Winkler <slinkp23@yahoo.com> wrote:
I have a Product I'm creating (python, not Zclass). I thought that I could get the parent object of an instance of my product using the aq_parent method. But AFAIKT, this only works on an "acquisition wrapper" of an object - not on the object itself??
Example: try this in Boring product:
class BrokenBoring( OFS.SimpleItem.Item, # A simple Principia object. Not Folderish. Persistent, # Make us persistent. Yaah! Acquisition.Implicit, # Be able to find things via acquisition. AccessControl.Role.RoleManager # Security manager. ): """ Can't acquire the parent... fooey. """ meta_type = 'Boring' # what do people think they're adding?
(snip)
def __init__(self, id, title=''): """initialise a new instance of Boring"""
(snip) try: assert hasattr(self, "aq_parent") except: print "Hey! This instance can't acquire parent!!"
When you add one of these in a folder, it prints the exception message in the log. In other words ... no aq_parent.
So I guess I need to get an acquisition wrapper to self, so I can acquire its parent? How do I do that? I can't figure it out from the DevGuide. Or Is there a less bletcherous solution? Help!
--
paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Florent Guillaume, Nuxeo SARL (Paris, France) +33 1 40 33 79 10 http://nuxeo.com mailto:fg@nuxeo.com
On Sunday 11 November 2001 09:05 pm, Paul Winkler allegedly wrote:
I have a Product I'm creating (python, not Zclass). I thought that I could get the parent object of an instance of my product using the aq_parent method. But AFAIKT, this only works on an "acquisition wrapper" of an object - not on the object itself??
Ummm, I don't see how acquisition could work any other way. Remember, at this point in the code, the object is not mounted in the ZODB yet, and therefore has no parent. There is a recipe on ZopeLabs regarding this issue . Check out: http://www.zopelabs.com/cookbook/995468614 [snip]
So I guess I need to get an acquisition wrapper to self, so I can acquire its parent? How do I do that? I can't figure it out from the DevGuide. Or Is there a less bletcherous solution? Help!
hth, /---------------------------------------------------\ Casey Duncan, Sr. Web Developer National Legal Aid and Defender Association c.duncan@nlada.org \---------------------------------------------------/
participants (3)
-
Casey Duncan -
Florent Guillaume -
Paul Winkler