reimplement WorkflowMethod in CMFCore

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30539 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b03a4536
...@@ -785,3 +785,43 @@ WorkflowTool.isTransitionPossible = WorkflowTool_isTransitionPossible ...@@ -785,3 +785,43 @@ WorkflowTool.isTransitionPossible = WorkflowTool_isTransitionPossible
WorkflowTool._reindexWorkflowVariables = lambda self, ob: \ WorkflowTool._reindexWorkflowVariables = lambda self, ob: \
hasattr(aq_base(ob), 'reindexObjectSecurity') and ob.reindexObjectSecurity() hasattr(aq_base(ob), 'reindexObjectSecurity') and ob.reindexObjectSecurity()
# Backward compatibility, as WorkflowMethod has been removed in CMFCore 2.2
from MethodObject import Method
class WorkflowMethod( Method ):
""" Wrap a method to workflow-enable it.
"""
_need__name__=1
def __init__(self, method, id=None, reindex=1):
self._m = method
if id is None:
id = method.__name__
self._id = id
# reindex ignored since workflows now perform the reindexing.
def __call__(self, instance, *args, **kw):
""" Invoke the wrapped method, and deal with the results.
"""
wf = getToolByName(instance, 'portal_workflow', None)
if wf is None or not hasattr(wf, 'wrapWorkflowMethod'):
# No workflow tool found.
try:
res = self._m(instance, *args, **kw)
except ObjectDeleted, ex:
res = ex.getResult()
else:
if hasattr(aq_base(instance), 'reindexObject'):
instance.reindexObject()
else:
res = wf.wrapWorkflowMethod(instance, self._id, self._m,
(instance,) + args, kw)
try:
from Products.CMFCore.WorkflowCore import WorkflowMethod
except ImportError:
from Products.CMFCore import WorkflowCore
# We're on CMF 2, where WorkflowMethod has been removed from CMFCore
WorkflowCore.WorkflowMethod = WorkflowCore.WorkflowAction = WorkflowMethod
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment