[Zope] Acquisition question
Dieter Maurer
dieter at handshake.de
Tue Jan 18 13:48:45 EST 2005
Garito wrote at 2005-1-18 09:12 +0100:
> ...
>I would like to execute something like:
>
>object.Render(args)
>
>where:
>object is an object inside a folder inside my product
>Render is the product's Render method acquired by the object
>
>the response is the id of my product instead the id of the object as
>expected
>
>Is this possible?
No, at least not with acquisition:
When you acquire a method, you change its "self".
This is necessary because the "self" of a method must
be an instance of the class defining the method.
The acquiring object usually does fulfill this requirement.
>How?
There are several ways:
* you use an ExternalMethod or PythonScript for "Render"
rather than a standard method definition
* you make "Render" an object with a "__call__" method.
In its "__call__" it can access the acquisition context
(your "object" above) with "self.aq_parent".
The product instance can be accessed with "self.aq_inner.aq_parent".
That this works, the "Render" object's class must inherit
from "Acquisition.[Im|Ex]plicit" and your product class
must inherit at least from "ExtensionClass.Base" (better
"Acquisition.[Im|Ex]plicit").
Note that the option above is a specialization of this one
(where you use predefined object classes with the required
features).
* You "reuse" the "Render" method of your product class
in your object via:
class MyObject(...):
Render = MyProduct.Render.im_func
>
>Thanks a lot!
>
>
--
Dieter
More information about the Zope
mailing list