[Zope-CMF] Re: Zope 3 events from workflow

Tres Seaver tseaver at palladion.com
Wed Dec 27 10:09:01 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Aspeli wrote:
> Hi guys,
> 
> Am I right in thinking that DCWorkflow does not send any Zope 3 events? 
> I'm not terribly familiar with that code, but some grepping suggests so.
> 
> Do you agree this would be useful? (I've got a pretty strong need for it 
>   for Plone 3, i.e. CMF 2.1 - I'm sure we can work around it in Plone, 
> but I'd rather do it properly)
> 
>  From what I can tell, something like this would work:
> 
> from zope.component.interfaces import IObjectEvent
> from zope.schema import TextLine
> 
> class IWorkflowEvent(IObjectEvent):
>      """A workflow related event
>      """
> 
>      wf_name = TextLine(title=u"The name of the workflow this event is 
> part of")
> 
>      transition = TextLine(title=u"The name of the transition taking place")
> 
>      state_before = TextLine(title=u"The object's state before the 
> transition")
> 
>      state_after = TextLine(title=u"The object's state after the 
> transition")
> 
> class IBeforeTransitionEvent(IWorkflowEvent):
>      """A transition is about to take place
>      """
> 
> class IAfterTransitionEvent(IWorkflowEvent):
>      """A transition has just taken place
>      """
> 
> ...
> 
> from zope.component import ObjectEvent
> from interfaces import IBeforeTransitionEvent, IAfterTransitionEvent
> 
> class WorkflowEvent(ObjectEvent):
> 
>      def __init__(self, object, wf_name, transition, state_before, 
> state_after):
>          self.object = object
>          self.wf_name = wf_name
>          self.transition = transition
>          self.state_before = state_before
>          self.state_after = state_after
> 
> class BeforeTransitionEvent(WorkflowEvent):
>      implements(IBeforeTransitionEvent)
> 
> class AfterTransitionEvent(WorkflowEvent):
>      implements(IAfterTransitionEvent)
> 
> ...
> 
> I'm not quite sure where the best place to execute the event is. One 
> option may be DCWorkflow/DCWorkflow.py, in notifyBefore() and 
> notifySuccess(). Here, though, I get a bit confused about how to 
> construct the wf_name and state_before/state_after parameters. I guess 
> they're not always needed, but they seem like they'd be useful to most 
> event handlers.
> 
> Would appreciate some suggestions or help to get this in, if you agree 
> it's a good idea (note, I don't have commit privs to CMF at this point).

Looks farily good overall.  I think one useful extension would be useful
to provide access to the same information currently exposed via
Products.DCWorkflow.Expression.StaTeChangeInfo (these are what the
guard expressions use):

  - The workflow object itself.

  - The transition object itself

  - The history of the object

  - Any keywords passed to the transition-trigger ('doActionFor')

Naming those attributes with the same names used in the expression
context might make porting some scripts / guard expressions to event
handlers simpler.

For full generality, we also need to allow the "before" handlers to veto
the transition, e.g. by raising WorkflowException.  Looking at the code,
it doesn't appear that the definition or the tool make any effort to
catch exceptions raised by transition scripts, so we should just emulate
how it handles them.



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFkoyN+gerLs4ltQ4RApyeAKCMJhA5IsP9j22cQakK7VsqbYQPMgCgnZ4+
QU+3RTSDGAW1vdaeCqvMgZM=
=Uq51
-----END PGP SIGNATURE-----



More information about the Zope-CMF mailing list