Commit ff42a339 authored by wenjie.zheng's avatar wenjie.zheng Committed by Sebastien Robin

Transition.py: add suffix removement to resolve workflow history generation problem.

parent 8e40911c
...@@ -165,6 +165,8 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject): ...@@ -165,6 +165,8 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject):
except KeyError: except KeyError:
raise WorkflowException('Destination state undefined: ' + new_state) raise WorkflowException('Destination state undefined: ' + new_state)
LOG(" 168 object '%s' will change from state '%s' to '%s'"%(document.getId(), old_state, new_state), WARNING, " in Transition.py")
# Execute the "before" script. # Execute the "before" script.
before_script_success = 1 before_script_success = 1
script_id = self.getBeforeScriptId() script_id = self.getBeforeScriptId()
...@@ -188,7 +190,7 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject): ...@@ -188,7 +190,7 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject):
# Do not proceed in case of failure of before script # Do not proceed in case of failure of before script
if not before_script_success: if not before_script_success:
former_status = old_state # Remain in state former_status = old_state # Remain in state
tool.setStatusOf(workflow.getId(), document, status_dict) tool.setStatusOf('_'.join(workflow.getId().split('_')[:-1]), document, status_dict)
sci = StateChangeInfo( sci = StateChangeInfo(
document, workflow, former_status, self, old_sdef, new_sdef, kwargs) document, workflow, former_status, self, old_sdef, new_sdef, kwargs)
# put the error message in the workflow history # put the error message in the workflow history
...@@ -208,7 +210,7 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject): ...@@ -208,7 +210,7 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject):
status_dict['undo'] = 0 status_dict['undo'] = 0
# Modify workflow history # Modify workflow history
status_dict[state_var] = new_state status_dict[state_var] = '_'.join(new_state.split('_')[:-1]) # remove suffix
object = workflow.getStateChangeInformation(document, state_object, transition=self) object = workflow.getStateChangeInformation(document, state_object, transition=self)
# update variables ========================================================= # update variables =========================================================
...@@ -225,11 +227,12 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject): ...@@ -225,11 +227,12 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject):
for vdef in workflow.objectValues(portal_type='Variable'): for vdef in workflow.objectValues(portal_type='Variable'):
id = vdef.getId() id = vdef.getId()
id_no_suffix = '_'.join(id.split('_')[:-1])
if vdef.for_status == 0: if vdef.for_status == 0:
continue continue
expr = None expr = None
if id in state_values: if id_no_suffix in state_values:
value = state_values[id] value = state_values[id_no_suffix]
elif id in tdef_exprs: elif id in tdef_exprs:
expr = tdef_exprs[id] expr = tdef_exprs[id]
elif not vdef.update_always and id in former_status: elif not vdef.update_always and id in former_status:
...@@ -252,7 +255,7 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject): ...@@ -252,7 +255,7 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject):
econtext = Expression_createExprContext(sci) econtext = Expression_createExprContext(sci)
expr = Expression(expr) expr = Expression(expr)
value = expr(econtext) value = expr(econtext)
status_dict[id] = value status_dict[id_no_suffix] = value
# Update all transition variables # Update all transition variables
if form_kw is not None: if form_kw is not None:
...@@ -262,11 +265,10 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject): ...@@ -262,11 +265,10 @@ class Transition(IdAsReferenceMixin('_transition'), XMLObject):
status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object) status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object)
# Generate Workflow History List # Generate Workflow History List
tool.setStatusOf(workflow.getId(), document, status_dict) tool.setStatusOf('_'.join(workflow.getId().split('_')[:-1]), document, status_dict)
### zwj: update Role mapping, also in Workflow, initialiseDocument() ### zwj: update Role mapping, also in Workflow, initialiseDocument()
workflow.updateRoleMappingsFor(document) workflow.updateRoleMappingsFor(document)
# Execute the "after" script. # Execute the "after" script.
script_id = self.getAfterScriptId() script_id = self.getAfterScriptId()
if script_id is not None: if script_id is not None:
......
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