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 Seaver          +1 540-429-0999          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


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

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

Reply via email to