[Checkins] SVN: CMF/branches/martin_workflow_events/CMFCore/ Apply
the CMFCore patch from http://www.zope.org/Collectors/CMF/461
Wichert Akkerman
wichert at wiggy.net
Thu Dec 28 22:04:05 EST 2006
Log message for revision 71667:
Apply the CMFCore patch from http://www.zope.org/Collectors/CMF/461
Changed:
U CMF/branches/martin_workflow_events/CMFCore/WorkflowCore.py
U CMF/branches/martin_workflow_events/CMFCore/WorkflowTool.py
U CMF/branches/martin_workflow_events/CMFCore/interfaces/__init__.py
U CMF/branches/martin_workflow_events/CMFCore/tests/test_WorkflowTool.py
-=-
Modified: CMF/branches/martin_workflow_events/CMFCore/WorkflowCore.py
===================================================================
--- CMF/branches/martin_workflow_events/CMFCore/WorkflowCore.py 2006-12-29 03:03:25 UTC (rev 71666)
+++ CMF/branches/martin_workflow_events/CMFCore/WorkflowCore.py 2006-12-29 03:04:02 UTC (rev 71667)
@@ -15,12 +15,20 @@
$Id$
"""
+from zope.interface import implements
+from zope.component.interfaces import ObjectEvent
+
+from Products.CMFCore.interfaces import IWorkflowActionEvent
+from Products.CMFCore.interfaces import IActionWillBeInvokedEvent
+from Products.CMFCore.interfaces import IActionRaisedExceptionEvent
+from Products.CMFCore.interfaces import IActionSucceededEvent
+
class WorkflowException( Exception ):
""" Exception while invoking workflow.
"""
+
-
class ObjectDeleted( Exception ):
""" Raise to tell the workflow tool that the object has been deleted.
@@ -49,3 +57,31 @@
def getNewObject(self):
return self._ob
+
+# Events
+
+class WorkflowActionEvent(ObjectEvent):
+ implements(IWorkflowActionEvent)
+
+ def __init__(self, object, workflow, action):
+ ObjectEvent.__init__(self, object)
+ self.workflow = workflow
+ self.action = action
+
+class ActionWillBeInvokedEvent(WorkflowActionEvent):
+ implements(IActionWillBeInvokedEvent)
+
+
+class ActionRaisedExceptionEvent(WorkflowActionEvent):
+ implements(IActionRaisedExceptionEvent)
+
+ def __init__(self, object, workflow, action, exc):
+ WorkflowActionEvent.__init__(self, object, workflow, action)
+ self.exc = exc
+
+class ActionSucceededEvent(WorkflowActionEvent):
+ implements(IActionSucceededEvent)
+
+ def __init__(self, object, workflow, action, result):
+ WorkflowActionEvent.__init__(self, object, workflow, action)
+ self.result = result
\ No newline at end of file
Modified: CMF/branches/martin_workflow_events/CMFCore/WorkflowTool.py
===================================================================
--- CMF/branches/martin_workflow_events/CMFCore/WorkflowTool.py 2006-12-29 03:03:25 UTC (rev 71666)
+++ CMF/branches/martin_workflow_events/CMFCore/WorkflowTool.py 2006-12-29 03:04:02 UTC (rev 71667)
@@ -25,6 +25,7 @@
from OFS.Folder import Folder
from OFS.ObjectManager import IFAwareObjectManager
from zope.interface import implements
+from zope.event import notify
from ActionProviderBase import ActionProviderBase
from interfaces import IConfigurableWorkflowTool
@@ -39,8 +40,10 @@
from WorkflowCore import ObjectDeleted
from WorkflowCore import ObjectMoved
from WorkflowCore import WorkflowException
+from WorkflowCore import ActionWillBeInvokedEvent
+from WorkflowCore import ActionRaisedExceptionEvent
+from WorkflowCore import ActionSucceededEvent
-
_marker = [] # Create a new marker object.
@@ -293,6 +296,7 @@
wfs = self.getWorkflowsFor(ob)
for wf in wfs:
wf.notifyBefore(ob, action)
+ notify(ActionWillBeInvokedEvent(ob, wf, action))
security.declarePrivate('notifySuccess')
def notifySuccess(self, ob, action, result=None):
@@ -301,6 +305,7 @@
wfs = self.getWorkflowsFor(ob)
for wf in wfs:
wf.notifySuccess(ob, action, result)
+ notify(ActionSucceededEvent(ob, wf, action, result))
security.declarePrivate('notifyException')
def notifyException(self, ob, action, exc):
@@ -309,6 +314,7 @@
wfs = self.getWorkflowsFor(ob)
for wf in wfs:
wf.notifyException(ob, action, exc)
+ notify(ActionRaisedExceptionEvent(ob, wf, action, exc))
security.declarePrivate('getHistoryOf')
def getHistoryOf(self, wf_id, ob):
@@ -516,6 +522,7 @@
reindex = 1
for w in wfs:
w.notifyBefore(ob, action)
+ notify(ActionWillBeInvokedEvent(ob, w, action))
try:
res = func(*args, **kw)
except ObjectDeleted, ex:
@@ -529,11 +536,13 @@
try:
for w in wfs:
w.notifyException(ob, action, exc)
+ notify(ActionRaisedExceptionEvent(ob, w, action, exc))
raise exc[0], exc[1], exc[2]
finally:
exc = None
for w in wfs:
w.notifySuccess(ob, action, res)
+ notify(ActionSucceededEvent(ob, w, action, res))
if reindex:
self._reindexWorkflowVariables(ob)
return res
Modified: CMF/branches/martin_workflow_events/CMFCore/interfaces/__init__.py
===================================================================
--- CMF/branches/martin_workflow_events/CMFCore/interfaces/__init__.py 2006-12-29 03:03:25 UTC (rev 71666)
+++ CMF/branches/martin_workflow_events/CMFCore/interfaces/__init__.py 2006-12-29 03:04:02 UTC (rev 71667)
@@ -17,6 +17,7 @@
from _content import *
from _tools import *
+from _events import *
import CachingPolicyManager
import Contentish
Modified: CMF/branches/martin_workflow_events/CMFCore/tests/test_WorkflowTool.py
===================================================================
--- CMF/branches/martin_workflow_events/CMFCore/tests/test_WorkflowTool.py 2006-12-29 03:03:25 UTC (rev 71666)
+++ CMF/branches/martin_workflow_events/CMFCore/tests/test_WorkflowTool.py 2006-12-29 03:04:02 UTC (rev 71667)
@@ -20,6 +20,10 @@
from OFS.SimpleItem import SimpleItem
+from zope.component import adapter, provideHandler
+from Products.CMFCore.interfaces import IActionWillBeInvokedEvent
+from Products.CMFCore.interfaces import IActionRaisedExceptionEvent
+from Products.CMFCore.interfaces import IActionSucceededEvent
class Dummy( SimpleItem ):
@@ -98,7 +102,18 @@
def notifyException( self, ob, action, exc ):
self.notified( 'exception' ).append( ( ob, action, exc ) )
+ at adapter(IActionWillBeInvokedEvent)
+def notifyBeforeHandler(evt):
+ evt.workflow.notified( 'before-evt' ).append( (evt.object, evt.action) )
+
+ at adapter(IActionSucceededEvent)
+def notifySuccessHandler(evt):
+ evt.workflow.notified( 'success-evt' ).append( (evt.object, evt.action, evt.result ) )
+ at adapter(IActionRaisedExceptionEvent)
+def notifyExceptionHandler(evt):
+ evt.workflow.notified( 'exception-evt' ).append( (evt.object, evt.action, evt.exc) )
+
class DummyContent( Dummy ):
meta_type = 'Dummy'
@@ -328,6 +343,8 @@
def test_notifyBefore( self ):
+ provideHandler(notifyBeforeHandler)
+
tool = self._makeWithTypesAndChain()
ob = DummyContent( 'dummy' )
@@ -337,9 +354,15 @@
notified = wf.notified( 'before' )
self.assertEqual( len( notified ), 1 )
self.assertEqual( notified[0], ( ob, 'action' ) )
+
+ notified = wf.notified( 'before-evt' )
+ self.assertEqual( len( notified ), 1 )
+ self.assertEqual( notified[0], ( ob, 'action' ) )
def test_notifySuccess( self ):
+ provideHandler(notifySuccessHandler)
+
tool = self._makeWithTypesAndChain()
ob = DummyContent( 'dummy' )
@@ -349,9 +372,15 @@
notified = wf.notified( 'success' )
self.assertEqual( len( notified ), 1 )
self.assertEqual( notified[0], ( ob, 'action', None ) )
+
+ notified = wf.notified( 'success-evt' )
+ self.assertEqual( len( notified ), 1 )
+ self.assertEqual( notified[0], ( ob, 'action', None ) )
def test_notifyException( self ):
+ provideHandler(notifyExceptionHandler)
+
tool = self._makeWithTypesAndChain()
ob = DummyContent( 'dummy' )
@@ -361,6 +390,10 @@
notified = wf.notified( 'exception' )
self.assertEqual( len( notified ), 1 )
self.assertEqual( notified[0], ( ob, 'action', 'exception' ) )
+
+ notified = wf.notified( 'exception-evt' )
+ self.assertEqual( len( notified ), 1 )
+ self.assertEqual( notified[0], ( ob, 'action', 'exception' ) )
def xxx_test_updateRoleMappings( self ):
"""
More information about the Checkins
mailing list