Hi Martin!

Martin Aspeli wrote:
If anyone has a more complete and concise code example for this use case, please let me know.

Ok. Wrote a prototype for you.

HTH, Yuppie

import logging
import os

from zope.component import queryMultiAdapter
from zope.interface import implements
from Products.GenericSetup.interfaces import IBody
from Products.GenericSetup.interfaces import ISetupEnviron
from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition

from Products import MyProduct # XXX: adjust

class SetupEnviron(object):

    """Context for body im- and exporter.


    def getLogger(self, name):
        return logging.getLogger('GenericSetup.%s' % name)

    def shouldPurge(self):
        return True

def install(self):
    wftool = getToolByName(self, 'portal_workflow')

    # create empty workflow
    obj_id = 'myWorkflow'
    wftool._setObject(obj_id, DCWorkflowDefinition(obj_id))
    obj = getattr(wftool, obj_id)

    # create import context
    environ = SetupEnviron()

    # get XML body
    product_path = os.path.split(MyProduct.__file__)[0]
    f_name = os.path.join(product_path, 'Extensions', 'definition.xml')
    f = file(f_name)
    body = f.read()

    # apply XML body to adapted workflow and environ
    adapted = queryMultiAdapter((obj, environ), IBody)
    adapted.body = body

    return 'done'

Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to