From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Abraham Arellano Tavara
sorry but which files properties are thoses.... and my original file is in the directory "Extensions" outside the Zope directory structure, there i use the open but i don't know how. Thanks for the help, Abraham.
Your External Method file is in the Extensions folder, which is normally part of your Zope installation's directory tree. Here is an example that I have used successfully. In some other directory, put a file containing the python code that you wish to execute. For example - Zope Extensions ...(other Zope directories) YourProject __init__.py YourPythonFile.py Data The __init__.py file turns that directory into a Python "package". "Data" is a subdirectory. In the __init__.py file, put code similar to the following - import os.path BASEPATH=os.path.dirname(__file__) DATA_PATH=os.path.join(BASEPATH,'Data') Now put YourProject into the Python path. There are several ways to do this, but the easiest is to write the absolute path to the directory on one line in a .pth file - say "project.pth". Put this file into the same directory as Zope's Python executable. In your external method, place code similar to the following - from YourProject import BASEPATH, DATA_PATH from YourProject import YourPythonFile.YourFunction Now the paths and functions are available to the whatever external method code you wish to write. I recommend just computing the right directories and calling the module's code, something like this - Import os.path def external_method(filename): yourPythonFile.yourFunction(os.path.join(DATA_PATH,'data.txt')) Of course, you can pass the REQUEST or whatever else you like as well. Cheers, Tom P
I am trying to create a ZClass instance via an external method. I have created a 'non-CatalogAware' ZClass called 'WebSites'. I can create, via the ZMI, an instance of the ZClass with no problem. However, when I try to create an instance via an external method I get an error. Here is the external method: def mytest(self): recid = "100" newobj = self.WebSitesChildData.manage_addProduct['SWV2'].WebSites.createInObjectMana ger(self, recid, REQUEST) return newobj where SWV2 is the product name; WebSitesChildData is the folder where I want the ZClass instance to be created; and 'recid' is the id I want to give the ZClass instance. The error I get is: Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Products.ExternalMethod.ExternalMethod, line 224, in __call__ - __traceback_info__: ((<Folder instance at 843e830>,), {}, None) Module /apps/zope/Extensions/jhtmp.py, line 15, in jhtmp Module ZClasses.ZClass, line 449, in createInObjectManager Module ZPublisher.mapply, line 77, in mapply AttributeError: get I am at a loss, because the createInObjectManager call works from the WebSites_add constructor, but not when called from the external method. Any ideas greatly appreciated! Jonathan
From: "Small Business Services" <toolkit@magma.ca>
I am trying to create a ZClass instance via an external method.
I have created a 'non-CatalogAware' ZClass called 'WebSites'. I can create, via the ZMI, an instance of the ZClass with no problem. However, when I try to create an instance via an external method I get an error.
Here is the external method:
def mytest(self): recid = "100" newobj =
self.WebSitesChildData.manage_addProduct['SWV2'].WebSites.createInObjectMana
ger(self, recid, REQUEST) return newobj
where SWV2 is the product name; WebSitesChildData is the folder where I want the ZClass instance to be created; and 'recid' is the id I want to give the ZClass instance.
The error I get is:
Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 88, in mapply Module ZPublisher.Publish, line 39, in call_object Module Products.ExternalMethod.ExternalMethod, line 224, in __call__ - __traceback_info__: ((<Folder instance at 843e830>,), {}, None) Module /apps/zope/Extensions/jhtmp.py, line 15, in jhtmp Module ZClasses.ZClass, line 449, in createInObjectManager Module ZPublisher.mapply, line 77, in mapply AttributeError: get
The following modification to the external method fixed the problem (I don't know why it fixed it, it just did): REQUEST = self.REQUEST REQUEST.set('id', recid) newobj = self.WebSitesChildData.manage_addProduct['SWV2'].WebSites.createInObjectMana ger(REQUEST['id'], REQUEST)
Small Business Services wrote at 2004-6-8 11:49 -0400:
... Here is the external method:
def mytest(self): recid = "100" newobj = self.WebSitesChildData.manage_addProduct['SWV2'].WebSites.createInObjectMana ger(self, recid, REQUEST) return newobj ... Module ZClasses.ZClass, line 449, in createInObjectManager Module ZPublisher.mapply, line 77, in mapply AttributeError: get
Apparently, the "REQUEST" above is not a request object (it does not have a "get" method). Try "self.REQUEST" instead. -- Dieter
participants (3)
-
Dieter Maurer -
Passin, Tom -
Small Business Services