[Grok-dev] Question regarding hurry.workflow

Sebastian Ware sebastian at urbantalk.se
Thu May 7 15:02:05 EDT 2009


Hi Tim (and anybody else interested in multiple workflow support)!

I have made a small experiment adding multiple workflow support to  
hurry.workflow using named utilities and namned adapters. It requires  
a "default" unnamed workflow to support versions. Maybe you could look  
at this and see if it might be useful.

The general idea is that you have an unnamed default workflow. Then  
you can add an arbitrary nr of named workflows. These can be set up  
with the same transitions as the default workflow or have other sets  
of transitions. I really just wanted to create a very light weight  
solution with a minimum of code changes.

I define my workflows like this:

#
# Default workflow (without name)

class Workflow(grok.GlobalUtility, workflow.Workflow):
     grok.provides(IWorkflow)

     def __init__(self):
         super(Workflow, self).__init__(create_workflow())

class WorkflowState(grok.Adapter, workflow.WorkflowState):
     grok.context(IProtonObject)
     grok.provides(interfaces.IWorkflowState)

class WorkflowInfo(grok.Adapter, workflow.WorkflowInfo):
     grok.context(IProtonObject)
     grok.provides(interfaces.IWorkflowInfo)

#
# Named workflow (called "sebastian")

class SpecialWorkflow(grok.GlobalUtility, workflow.Workflow):
     grok.name('sebastian')
     grok.provides(IWorkflow)

     def __init__(self):
         super(SpecialWorkflow, self).__init__(create_workflow())

class SpecialState(grok.Adapter, workflow.WorkflowState):
     grok.context(IProtonObject)
     grok.provides(interfaces.IWorkflowState)
     grok.name("sebastian")
     workflow_name = "sebastian"

class SpecialInfo(grok.Adapter, workflow.WorkflowInfo):
     grok.context(IProtonObject)
     grok.provides(interfaces.IWorkflowInfo)
     grok.name("sebastian")
     workflow_name = "sebastian"

#
# Getting a workflow utility
from zope.component import getUtility
default_wu = getUtility(IWorkflow)
named_wu = getUtility(IWorkflow, "sebastian")

#
# Manipulating an object
from zope.component import getAdapter
default_wi = IWorkflowInfo(item)
named_wi = getAdapter(item, IWorkflowInfo, name="sebastian")


Attached is the updated hurry.workflow.workflow(.py) file. I also  
added the attribute "workflow_name" to interface.py for both  
IWorkflowInfo and IWorkflowState.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: workflow.py
Type: text/x-python-script
Size: 13128 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20090507/953a78cb/attachment.bin 
-------------- next part --------------



Mvh Sebastian


3 maj 2009 kl. 00.43 skrev Tim Cook:
>
> Since you were discussing ore.workflow and it having multiple  
> workflows
> I decided to take a look.
>
> I will soon need this functionality.



More information about the Grok-dev mailing list