Commit dab41b23 authored by wenjie.zheng's avatar wenjie.zheng

patches/WorkflowTool.py: add doActionFor's compability.

parent 3a625816
...@@ -25,7 +25,7 @@ from Products.CMFCore.WorkflowCore import ObjectMoved, ObjectDeleted ...@@ -25,7 +25,7 @@ from Products.CMFCore.WorkflowCore import ObjectMoved, ObjectDeleted
from Products.CMFCore.WorkflowCore import WorkflowException from Products.CMFCore.WorkflowCore import WorkflowException
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD
from Products.CMFCore.utils import Message as _
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, AutoQuery, ComplexQuery, NegatedQuery from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, AutoQuery, ComplexQuery, NegatedQuery
from Products.CMFCore.utils import _getAuthenticatedUser from Products.CMFCore.utils import _getAuthenticatedUser
...@@ -961,32 +961,49 @@ def _isJumpToStatePossibleFor(self, ob, state_id, wf_id=None): ...@@ -961,32 +961,49 @@ def _isJumpToStatePossibleFor(self, ob, state_id, wf_id=None):
return True return True
return False return False
def _doActionFor(self, ob, action, wf_id=None, *args, **kw): def _doActionFor(self, ob, action, wf_id=None, *args, **kw):
""" Perform the given workflow action on 'ob'. ###raise NotImplementedError ("Redefine doActionFor") ###zwj: it workfs!
""" wfs = self.getWorkflowsFor(ob)
###raise NotImplementedError ("Redefine doActionFor") ###zwj: it workfs! workflow_list = ob.getTypeInfo().getTypeERP5WorkflowList()
wfs = self.getWorkflowsFor(ob) case = 1
if wfs is None:
wfs = () if wfs is None:
if wf_id is None: wfs = ()
if not wfs: case = 2
raise WorkflowException(_(u'No workflows found.'))
found = 0 if wf_id is None:
for wf in wfs: if wfs == () and workflow_list == []:
if wf.isActionSupported(ob, action, **kw): raise WorkflowException(_(u'No workflows found.'))
found = 1 found = 0
break for wf in wfs:
if not found: if wf.isActionSupported(ob, action, **kw):
msg = _(u"No workflow provides the '${action_id}' action.", found = 1
mapping={'action_id': action}) case = 1
raise WorkflowException(msg) break
for workflow_id in workflow_list:
workflow = self.getPortalObject().getDefaultModule('Workflow')._getOb(workflow_id)
if workflow.isActionSupported(ob, action, **kw):
found = 1
case = 2
break
if not found:
msg = _(u"No workflow provides the '${action_id}' action.",mapping={'action_id': action})
raise WorkflowException(msg)
else:
if case == 1:
wf = self.getWorkflowById(wf_id)
#wf = getattr(self, 'getWorkflowById', None)(wf_id)
else: else:
wf = self.getWorkflowById(wf_id) workflow = self.getPortalObject().getDefaultModule('Workflow')._getOb(wf_id, None)
if wf is None: if wf is None and workflow is None:
raise WorkflowException( raise WorkflowException(_(u'Requested workflow definition not found.'))
_(u'Requested workflow definition not found.'))
return self._invokeWithNotification( if case == 1:
wfs, ob, action, wf.doActionFor, (ob, action) + args, kw) return self._invokeWithNotification(wfs, ob, action, wf.doActionFor, (ob, action) + args, kw)
else:
return workflow.doActionFor(ob, action)
WorkflowTool._jumpToStateFor = _jumpToStateFor WorkflowTool._jumpToStateFor = _jumpToStateFor
WorkflowTool._isJumpToStatePossibleFor = _isJumpToStatePossibleFor WorkflowTool._isJumpToStatePossibleFor = _isJumpToStatePossibleFor
......
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