[Zope-CMF] Re: Programmatically installing a workflow script

Raphael Ritz r.ritz at biologie.hu-berlin.de
Wed Sep 1 04:20:33 EDT 2004


Dan Fairs wrote:
> Hi,
> 
> I'm trying to programmatically add a Python script in my product's
> Install.py and assign it to run before a DCWorkflow transition takes
> place. I've managed to add a workflow programmatically (thanks to
> dumpDCWorkflow) but I can't see how you add a script.
> 
> I've seen that PythonScript.py has a manage_addPythonScript, but I don't
> know how to call it I've tried:
> 
> portal.portal_workflow.workflow.scripts.manage_addPythonScript()
> ... and variations on the theme, but I can't get it to work.
> 
> Does anyone have any examples?
> 

Another example is provided by the 'CompoundWorkflow'
found in the MySite tutorial from
http://www.neuroinf.de/LabTools/MySite

Raphael

<code fragment>
from Products.PythonScripts.PythonScript import PythonScript

def addScript(wf):
     """
     add a script for exectution on some tranistions to
     handle sub-objects
     """
     myscript = PythonScript('plusChildren')
     myscript.write(
"""## Script (Python) "plusChildren"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=state_change=None
##title=move children as well
##
obj = getattr(state_change, 'object')
transition_id = getattr(state_change, 'transition').getId()
     ... # skipped some code

     script_folder = getattr(wf, 'scripts')
     if script_folder:
         script_folder._setObject("plusChildren", myscript)
         transitions = getattr(wf, 'transitions')
         for transition in transitions.objectValues():
             if transition.getId() != 'submit':
                 transition.after_script_name='plusChildren'

def createCompoundWorkflow(id):
     ob=DCWorkflowDefinition(id)
     setupCompoundWorkflow(ob)
     ob.setProperties(title='Compound Workflow')
     configureEventPermissions(ob)
     addScript(ob)
     return ob

addWorkflowFactory( createCompoundWorkflow, id='compound_workflow'
                   , title='Compound Workflow')

</code fragment>



More information about the Zope-CMF mailing list