Create and Use an External Method

by Tom Elliott last modified Dec 30, 2008 03:03 PM
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.
  1. Inspect your Plone installation and find the Zope folder. For example, on Windows, you might find: C:\Program Files\Plone 2\Zope.
  2. If there is not a folder named "Extensions" in your Zope folder, create one.
  3. Put a copy of the module (e.g., blah.py) containing the function you want to call (e.g., argh()) in this directory.
  4. (Re)start Zope.
  5. 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).
  6. In the ZMI, on the "Contents" tab for the context folder, select the combo box next to the "Add" button and choose "External Method".
  7. Give the new external method the necessary properties, for example:
    1. id: run_argh
    2. title (optional): Run the argh function
    3. module name: blah
    4. function name: argh
  8. Click the "Add" button
  9. You can now call your external method through the web, e.g.: http://localhost/dog/leg/run_argh
  10. 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.