支持 DCWorkflow 的脚本仅支持通过 Web 可添加的对象,这将您限制为那里的外部方法。
更好的选择是改用工作流事件。对于每个工作流转换,会触发两个事件:
Products.DCWorkflow.interfaces.IAfterTransitionEvent
Products.DCWorkflow.interfaces.IBeforeTransitionEvent
如果您订阅其中任何一个事件,则可以过滤正确的工作流程和转换,以对来自受信任代码的转换做出反应。
每个触发的事件都具有以下属性:
object
: 工作流对象
workflow
:当前适用的工作流对象
old_state
: 一个Products.DCWorkflow.States.StateDefinition
对象
new_state
: 另一个Products.DCWorkflow.States.StateDefinition
对象
transition
: 一个Products.DCWorkflow.Transititions.TransitionDefinition
对象
status
:具有当前工作流变量的字典
kwargs
: 传入 change-transition 调用的额外参数字典。
使用 ZCML 注册订阅者:
<subscriber
provides="zope.component.testfiles.adapter.IS"
factory=".youreventsmodule.aftertransition_handler"
for="Products.DCWorkflow.interfaces.IAfterTransitionEvent"
/>
或者,因为转换事件是对象事件,所以如果它适用于您的对象,则仅侦听转换事件:
<subscriber
provides="zope.component.testfiles.adapter.IS"
factory=".youreventsmodule.container_aftertransition_handler"
for=".interfaces.IMyContainerType
Products.DCWorkflow.interfaces.IAfterTransitionEvent"
/>
IMyContainerType
它仅为具有接口的对象上的转换事件注册您的处理程序。
处理程序将是:
def aftertransition_handler(event):
# handle all transition events, ever
或者,将其限制为一个对象接口时:
def aftertransition_handler(obj, event):
# handle all transition events for our container interface