Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Tips / External Method

External Method

Zope 提供 External Method 機制,用來透過網頁執行 Python 程式,並能處理檔案系統層面的資料。

http://plone.org/documentation/kb/create-and-use-an-external-method
http://www.exsoft.net/blog/entry/57qvuw

example: whois

add external method while installing product

in profiles/default create import_steps.xml

Import easysearch settings

in the product create setuphandlers.py file like this

# created by tareq alam
# tareq.mist@gmail.com
# www.commitmentsoft.com
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_hasattr
from Products.Archetypes.public import listTypes

 

def importVarious(context):
"""
Final easysearch import steps.
"""

 

site = context.getSite()
invokeFactory = getToolByName(site, 'invokeFactory')
manage_delObjects = getToolByName(site, 'manage_delObjects')
#getattr = getToolByName(site, 'getattr')

 

try:
manage_delObjects("reportExternalMethods")
except:
pass
Newfolder = invokeFactory("Folder", id="reportExternalMethods", title="reportExternalMethods",path='/')
Newfolderobj = getattr(site, Newfolder, None)
manage_addProduct = getToolByName(Newfolderobj, 'manage_addProduct')

 

em = manage_addProduct['ExternalMethod']
manage_addExternalMethod = getToolByName(em, 'manage_addExternalMethod')
manage_addExternalMethod('imageexample', 'imageexample', 'easysearch.imageexample', 'imageexample')
manage_addExternalMethod('createResultPy', 'createResultPy', 'easysearch.createResultPy', 'createResultPy')

 

#em = context.manage_addProduct['ExternalMethod']

 

 

 

 

 

 

now restart and install product, this will create a folder reportExternalMethods in root .. and also create two external methods in that folder

Prevent External Method Directory From Removed By Rerunning Buildout

TypeError: expected string or Unicode object, NoneType found