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

Workflow.py: fix in getInfo, variable guard hasn't been checked properly; add...

Workflow.py: fix in getInfo, variable guard hasn't been checked properly; add _getStatusOf which get the workflow history correctly, and it is used to replace getCurrentStatusDict which does the same thing after correction. history key now directly get from workflow reference.
parent be615b6b
......@@ -67,7 +67,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
"""
A ERP5 Workflow.
"""
id = ''
meta_type = 'ERP5 Workflow'
portal_type = 'Workflow'
_isAWorkflow = True # DCWorkflow Tool compatibility
......@@ -110,7 +110,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
"""
Generate a key used in the workflow history.
"""
history_key = self.unrestrictedTraverse(self.getRelativeUrl()).getReference()
history_key = self.getReference()
return history_key
def _updateWorkflowHistory(self, document, status_dict):
......@@ -136,17 +136,6 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
# XXX this _p_changed is apparently not necessary
#document.workflow_history._p_changed = 1
def getCurrentStatusDict(self, document):
"""
Get the current status dict.
"""
workflow_key = self._generateHistoryKey()
workflow_history = self.getHistoryOf(workflow_key, document)
# Copy is requested
if workflow_history:
return workflow_history[-1].copy()
return {}
def getDateTime(self):
"""
Return current date time.
......@@ -437,36 +426,45 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
Allows the user to request information provided by the
workflow. This method must perform its own security checks.
'''
state_var = self.getStateVariable()
if name == state_var:
return ob._getDefaultAcquiredValue(state_var).getId()
for x in self.objectValues(portal_type='Variable'):
if x.getReference() == name:
vdef = x
break
status_dict = self.getCurrentStatusDict(ob)
former_status = self._getOb(status_dict[state_var], None)
if former_status == None:
former_status = self.getSourceValue()
if vdef.info_guard is not None and not vdef.info_guard.check(
if name == self.getStateVariable():
return self._getWorkflowStateOf(ob, 1)
vdef = self.getVariableValueList().get(name)
if vdef.getInfoGuard() is not None and not vdef.getInfoGuard().check(
getSecurityManager(), self, ob):
return default
status = self._getStatusOf(ob)
if status is not None and status.has_key(name):
value = status[name]
if status_dict is not None and name in status_dict:
value = status_dict[name]
# Not set yet. Use a default.
if vdef.default_expr is not None:
ec = createExprContext(StateChangeInfo(ob, self, former_status))
expr = Expression(vdef.default_expr)
value = expr(ec)
elif vdef.default_expr is not None:
ec = createExprContext(StateChangeInfo(ob, self, status))
value = Expression(vdef.default_expr)(ec)
else:
value = vdef.default_value
return value
def getCurrentStatusDict(self, document):
"""
Get the current status dict. It's the same as _getStatusOf.
"""
workflow_key = self._generateHistoryKey()
workflow_history = self.getParent().getHistoryOf(workflow_key, document)
# Copy is requested
if workflow_history:
return workflow_history[-1].copy()
return {}
def _getStatusOf(self, ob):
tool = self.getParent()
status = tool.getStatusOf(self.getId(), ob)
if status is None:
return {}
else:
# Copy is requested
return status.copy()
def _getWorkflowStateOf(self, ob, id_only=0):
tool = getToolByName(self, 'portal_workflow')
id_no_suffix = self.getReference()
......@@ -591,7 +589,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
# Figure out the old and new states.
state_var = self.getStateVariable()
status_dict = self.getCurrentStatusDict(document)
status_dict = self._getStatusOf(document)
current_state_value = self._getWorkflowStateOf(document, id_only=0)
if current_state_value == None:
......@@ -998,7 +996,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if old_state == new_state_id:
# Object is already in expected state
return
former_status = self.getCurrentStatusDict(ob)
former_status = self._getStatusOf(ob)
new_sdef = self._getOb(new_state_id, None)
if new_sdef is None:
......@@ -1071,7 +1069,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
res = {}
# Always provide the state variable.
state_var = self.getStateVariable()
status = self.getCurrentStatusDict(ob)
status = self._getStatusOf(ob)
for id, vdef in self.getVariableValueList().iteritems():
if vdef.for_catalog:
if status.has_key(id):
......
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