Commit 49ae3287 authored by wenjie.zheng's avatar wenjie.zheng

patches/WOrkflowTool.py: add ERP5Workflow compatibility to getInfoFor.

parent 9c909ece
...@@ -38,6 +38,8 @@ from itertools import izip ...@@ -38,6 +38,8 @@ from itertools import izip
from MySQLdb import ProgrammingError, OperationalError from MySQLdb import ProgrammingError, OperationalError
from DateTime import DateTime from DateTime import DateTime
_marker = [] # Create a new marker object.
def DCWorkflowDefinition_notifyWorkflowMethod(self, ob, transition_list, args=None, kw=None): def DCWorkflowDefinition_notifyWorkflowMethod(self, ob, transition_list, args=None, kw=None):
''' '''
Allows the system to request a workflow action. This method Allows the system to request a workflow action. This method
...@@ -961,7 +963,6 @@ def _isJumpToStatePossibleFor(self, ob, state_id, wf_id=None): ...@@ -961,7 +963,6 @@ 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):
wfs = self.getWorkflowsFor(ob) wfs = self.getWorkflowsFor(ob)
workflow_list = ob.getTypeInfo().getTypeERP5WorkflowList() workflow_list = ob.getTypeInfo().getTypeERP5WorkflowList()
...@@ -1003,6 +1004,56 @@ def _doActionFor(self, ob, action, wf_id=None, *args, **kw): ...@@ -1003,6 +1004,56 @@ def _doActionFor(self, ob, action, wf_id=None, *args, **kw):
else: else:
return workflow.doActionFor(ob, action) return workflow.doActionFor(ob, action)
def _getInfoFor(self, ob, name, default=_marker, wf_id=None, *args, **kw):
wfs = self.getWorkflowsFor(ob)
workflow_list = ob.getTypeInfo().getTypeERP5WorkflowList()
case = 1
if wfs is None:
case = 2
if wf_id is None:
if wfs is None and workflow_list == []:
if default is _marker:
raise WorkflowException(_(u'No workflows found.'))
else:
return default
found = 0
for wf in wfs:
if wf.isInfoSupported(ob, name):
found = 1
case = 1
break
for workflow_id in workflow_list:
workflow = self.getPortalObject().getDefaultModule('Workflow')._getOb(workflow_id)
if workflow.isInfoSuported(ob, name):
found = 1
case = 2
break
if not found:
if default is _marker:
msg = _(u"No workflow provides '${name}' information.",
mapping={'name': name})
raise WorkflowException(msg)
else:
return default
else:
if case == 1:
wf = self.getWorkflowById(wf_id)
else:
wf = self.getPortalObject().getDefaultModule('Workflow')._getOb(wf_id)
if wf is None:
if default is _marker:
raise WorkflowException(
_(u'Requested workflow definition not found.'))
else:
return default
res = wf.getInfoFor(ob, name, default, *args, **kw)
if res is _marker:
msg = _(u'Could not get info: ${name}', mapping={'name': name})
raise WorkflowException(msg)
return res
WorkflowTool._jumpToStateFor = _jumpToStateFor WorkflowTool._jumpToStateFor = _jumpToStateFor
WorkflowTool._isJumpToStatePossibleFor = _isJumpToStatePossibleFor WorkflowTool._isJumpToStatePossibleFor = _isJumpToStatePossibleFor
WorkflowTool.doActionFor = _doActionFor WorkflowTool.doActionFor = _doActionFor
WorkflowTool.getInfoFor = _getInfoFor
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