Tareq Alam

i have promises to keep and miles to go before i sleep – Robert Frost

how to add external method while installing product in plone May 6, 2009

Filed under: 1 — tareqalam @ 11:27 am
Tags: , , , ,

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