[Zope] inheritance and aqusition question

Paul Winkler pw_lists at slinkp.com
Fri Feb 3 10:48:46 EST 2006


On Fri, Feb 03, 2006 at 02:04:49PM +0100, Roman Klesel wrote:
> Hello Andrew,
> 
> thanks for your reply.
> 
> Andrew Milton schrieb:
> > 
> > One (or more) of the following two;
> > 
> > Your class isn't yet fully instantiated and Acquisition wrapped, this normally
> > doesn't occur until your class is inside the ZODB. 
> 
> That's true! And it's nor supposed to be. It's only a temporary Object that's being destroyed
> after the method in which it's created has finished processing.
> 
> >You generally need to use a
> > 'post init' method to do a 2-stage init so that subitems can acquire items.
> > There are Zope hooks you can use (manage_afterAdd), or you can call your
> > own methods in the "manage_add" Factory method of your product.
> > 
> > If this is what you are doing then it's probably;
> > 
> > The importSingle class must be an attribute of the Controller class for
> > Acquisition to work in this way. 
> 
> I wouldn't like to do that either, because I don't want that object to persist.
> 
> Probably I just do things in the wrong way. What I wnat to do is:
> 
> In the temporary object:
> 
> try:
>    h=open('file',r)
> except:
>    em = 'File %s does not exist' % file
>    return REQUEST.RESPONSE.redirect(self.manage_editSettings(REQUEST), em)

... and you want manage_editSettings to be acquired, ok.
As has been suggested, you probably don't have an acquisition
wrapper set up.  You can create one without persisting
your wrapped object like so:

class Controller(...):

    def some_method(self, ...):
        ...
        temp = importSingle(...)
        temp = temp.__of__(self)   # this creates the wrapper
        temp.someMethod()
        ...

Once you have a wrapper, you can call methods on it and
those methods can successfully acquire things from the acquisition
context (in this case the Controller instance).

This example assumes that your Controller is responsible for
instantiating the importSingle instances.

But having said that, I too wonder why use acquisition for this.
Why not just pass in a reference to the Controller instance
and call methods on it explicitly? 

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list