Hi all I create a product. It have a method like this: def Render(self, args): """Render method""" return self.getId() In these folderish product I put some folders and some objects inside them 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? How? Thanks a lot!
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
Dieter Maurer escribió:
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!
Thank you Dieter I think I choose to obtain a python script and the use the context object (instead of self) See u!
Garito wrote:
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? How?
What's the python you're using to obtain 'object'? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris Withers -
Dieter Maurer -
Garito