Dynamically add an external method at startup
I'm trying to exploit a product's initialize method and have it add external methods to a zope installation. What I've cobbled together so far is: import Zope import ZODB from Products.ExternalMethod.ExternalMethod import ExternalMethod import OFS def addExternalMethod(self, id, title, module, function, REQUEST=None): """Add an external method to a folder""" id=str(id) title=str(title) module=str(module) function=str(function) i=ExternalMethod(id,title,module,function) #self._setObject(id,i) def initialize(context): """Initialize the product""" addExternalMethod(None, "MethID", "MethTitle", "Module", "Function") I don't get errors at start up, and of course my "product" isn't registered, but can anyone tell me what self wants to be in addExternalMethod and how I could get there from initialize(context)? Thanks, -- Emile van Sebille emile@fenx.com ---------
Hi,
def addExternalMethod(self, id, title, module, function, REQUEST=None): """Add an external method to a folder""" id=str(id) title=str(title) module=str(module) function=str(function) i=ExternalMethod(id,title,module,function) #self._setObject(id,i)
I don't get errors at start up, and of course my "product" isn't registered, but can anyone tell me what self wants to be in addExternalMethod and how I could get there from initialize(context)?
self wants to be the folder where you want to add the ExternalMethod. ObjectManagers, thus also Folders, have a method _setObject that allow you to add objects to them. Phil
Philipp von Weitershausen
Emile van Sebille
def addExternalMethod(self, id, title, module, function, REQUEST=None): """Add an external method to a folder""" id=str(id) title=str(title) module=str(module) function=str(function) i=ExternalMethod(id,title,module,function) #self._setObject(id,i)
I don't get errors at start up, and of course my "product" isn't registered, but can anyone tell me what self wants to be in addExternalMethod and how I could get there from initialize(context)?
self wants to be the folder where you want to add the ExternalMethod. ObjectManagers, thus also Folders, have a method _setObject that allow you to add objects to them.
Thanks Philipp. That answers one of the questions. Can you tell me how to acquire a reference to a folder given that I've got my hands on context and can import Zope, etc? Again, thanks for your help. -- Emile van Sebille emile@fenx.com ---------
Emile van Sebille
Thanks Philipp. That answers one of the questions. Can you tell me how to acquire a reference to a folder given that I've got my hands on context and can import Zope, etc?
I found a post in the archives from Martijn Pieters that put me on the right track so I've got something that works for me: from Products.ExternalMethod.ExternalMethod import ExternalMethod def addExternalMethod(self, id, title, module, function, REQUEST=None): """Add an external method to a folder""" id=str(id) title=str(title) module=str(module) function=str(function) i=ExternalMethod(id,title,module,function) self._setObject(id,i) def initialize(context): """Initialize""" addExternalMethod(context._ProductContext__app, "id", "title", "module", "func") -- Emile van Sebille emile@fenx.com ---------
participants (2)
-
Emile van Sebille -
Philipp von Weitershausen