Create and Use an External Method
Zope External Methods allow you to write and register python scripts that can be called through-the-web to manipulate your Zope/Plone instance. The main difference is that these can do things with a much higher privilege level since they are located on the file system, not in the web interface.
- Inspect your Plone installation and find the Zope folder. For example, on Windows, you might find: C:\Program Files\Plone 2\Zope.
- If there is not a folder named "Extensions" in your Zope folder, create one.
- Put a copy of the module (e.g., blah.py) containing the function you want to call (e.g., argh()) in this directory.
- (Re)start Zope.
- Open the ZMI (e.g., http://localhost/manage) and navigate to the folder where you want the external method to reside (e.g., /dog/leg). This location will provide the run context for your script (i.e., a "self" paramater on the argh() function will be populated with a reference to this folder). Note: don't use the ZMI to create new folders; instead, do it "through-the-Plone" (see How-to: Changing Tabs).
- In the ZMI, on the "Contents" tab for the context folder, select the combo box next to the "Add" button and choose "External Method".
- Give the new external method the necessary properties, for example:
- id: run_argh
- title (optional): Run the argh function
- module name: blah
- function name: argh
- Click the "Add" button
- You can now call your external method through the web, e.g.: http://localhost/dog/leg/run_argh
- If the function called by your external method requires parameters, you can supply these after a question mark, for example: http://localhost/dog/leg/run_argh?voice=piratical
This how-to was helped along by http://www.zope.org/Documentation/How-To/ExternalMethods and Sean Gillies.