How to get "context" in an instance method
This probably has a simple solution, but I'm probably going to have to sleep on it to find it. Thanks in advance for any help... I have a class derived from ObjectManager and SimpleItem.Item which defines a directory structure under it. Something like this: class MyZopeProduct( ObjectManager.ObjectManager, SimpleItem.Item ) # ... def myFunc(self, context=None, REQUEST=None): doSomethingWithContext(context) After I add an instance of MyZopeProduct to my root folder (as myinstance) I can go to http://me:8080/myinstance and things work as expected. If there is a folder inside my instance called 'folder' then I can also go to http://me:8080/myinstance/folder and everything works fine. What I can't figure out is how to go to http://me:8080/myinstance/folder/myFunc and have the context (the folder instance object) passed into my script. I've been hunting through the source for something similar but I can't find it. It's probably something simple, but I just can't seem to find how to get the context. When I call myFunc the REQUEST variable is inserted, but the context always comes back as None. All other Acquisition-related functionality seems to work for "folder", like pulling 'index_html' out of the root because it doesn't have one of its own (and neither does "myinstance") I want to be able to use Acquisition within my Python Product code... Is it possible? Thanks in advance! -Paul _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com
Paul Tiemann writes:
This probably has a simple solution, but I'm probably going to have to sleep on it to find it. Thanks in advance for any help...
I have a class derived from ObjectManager and SimpleItem.Item which defines a directory structure under it. Something like this:
class MyZopeProduct( ObjectManager.ObjectManager, SimpleItem.Item ) # ... def myFunc(self, context=None, REQUEST=None): doSomethingWithContext(context)
After I add an instance of MyZopeProduct to my root folder (as myinstance) I can go to http://me:8080/myinstance and things work as expected. If there is a folder inside my instance called 'folder' then I can also go to http://me:8080/myinstance/folder and everything works fine.
What I can't figure out is how to go to http://me:8080/myinstance/folder/myFunc and have the context (the folder instance object) passed into my script.
You can try: "self.aq_parent". It's not sure, that it will work, though. If it does not, you could use a "ComputedAttribute(myFunc,1)" and pass the information explicitly. Dieter
participants (2)
-
Dieter Maurer -
Paul Tiemann