Commit 9b5f7282 authored by wenjie.zheng's avatar wenjie.zheng

Transition.py & Workflow.py: Improve workflow history generation.

parent bbdcfa3d
...@@ -77,7 +77,7 @@ class Transition(XMLObject): ...@@ -77,7 +77,7 @@ class Transition(XMLObject):
# Get variable values # Get variable values
state_bc_id = workflow.getStateBaseCategory() state_bc_id = workflow.getStateBaseCategory()
status_dict = workflow.getCurrentStatusDict(document) status_dict = workflow.getCurrentStatusDict(document)
state_object = document.unrestrictedTraverse(status_dict[state_bc_id]) state_object = workflow._getOb(status_dict[state_bc_id])
old_state = state_object.getId() old_state = state_object.getId()
new_state = document.unrestrictedTraverse(self.getDestination()).getId() new_state = document.unrestrictedTraverse(self.getDestination()).getId()
...@@ -135,9 +135,11 @@ class Transition(XMLObject): ...@@ -135,9 +135,11 @@ class Transition(XMLObject):
self.getParent().updateRoleMappingsFor(document) self.getParent().updateRoleMappingsFor(document)
status_dict['undo'] = 0 status_dict['undo'] = 0
status_dict['action'] = self.getId()
# Modify workflow history # Modify workflow history
status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0] #status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0]
status_dict[state_bc_id] = new_state
object = workflow.getStateChangeInformation(document, state_object, transition=self) object = workflow.getStateChangeInformation(document, state_object, transition=self)
# Update all variables # Update all variables
...@@ -154,6 +156,7 @@ class Transition(XMLObject): ...@@ -154,6 +156,7 @@ class Transition(XMLObject):
# Update all transition variables # Update all transition variables
if form_kw is not None: if form_kw is not None:
object.REQUEST.other.update(form_kw) object.REQUEST.other.update(form_kw)
# zwj: The transition variable is replaced by a base category; thus this part is not in use.
for variable in self.contentValues(portal_type='Transition Variable'): for variable in self.contentValues(portal_type='Transition Variable'):
status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object) status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object)
...@@ -179,52 +182,6 @@ class Transition(XMLObject): ...@@ -179,52 +182,6 @@ class Transition(XMLObject):
else: else:
return new_sdef return new_sdef
""" the old execution
if form_kw is None:
form_kw = {}
workflow = self.getParentValue()
# Get variable values
state_bc_id = workflow.getStateBaseCategory()
status_dict = workflow.getCurrentStatusDict(document)
state_object = document.unrestrictedTraverse(status_dict[state_bc_id])
# Call the before script
self._executeBeforeScript(document, workflow, state_object, form_kw=form_kw)
# Modify the state
self._changeState(document)
### zwj: update Role mapping, also in Workflow, initialiseDocument()
self.getParent().updateRoleMappingsFor(document)
status_dict['undo'] = 0
# Modify workflow history
status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0]
object = workflow.getStateChangeInformation(document, state_object, transition=self)
# Update all variables
for variable in workflow.contentValues(portal_type='Variable'):
if variable.getAutomaticUpdate():
# if we have it in form get it from there
# otherwise use default
variable_title = variable.getTitle()
if variable_title in form_kw:
status_dict[variable_title] = form_kw[variable_title]
else:
status_dict[variable_title] = variable.getInitialValue(object=object)
# Update all transition variables
if form_kw is not None:
object.REQUEST.other.update(form_kw)
for variable in self.contentValues(portal_type='Transition Variable'):
status_dict[variable.getCausalityTitle()] = variable.getInitialValue(object=object)
workflow._updateWorkflowHistory(document, status_dict)
# Call the after script
self._executeAfterScript(document, workflow, state_object, form_kw=form_kw)
"""
def _changeState(self, document): def _changeState(self, document):
""" """
Change the state of the object. Change the state of the object.
...@@ -235,48 +192,6 @@ class Transition(XMLObject): ...@@ -235,48 +192,6 @@ class Transition(XMLObject):
state_bc_id = self.getParentValue().getStateBaseCategory() state_bc_id = self.getParentValue().getStateBaseCategory()
document.setCategoryMembership(state_bc_id, state) document.setCategoryMembership(state_bc_id, state)
def _executeAfterScript(self, document, workflow, state_object, form_kw=None):
"""
Execute post transition script.
"""
former_status = state_object.getId()
old_sdef = state_object
new_sdef = document.unrestrictedTraverse(self.getDestination())
kwargs = form_kw
sci = StateChangeInfo(
document, workflow, former_status, self, old_sdef, new_sdef, kwargs)
if form_kw is None:
form_kw = {}
script_id = self.getAfterScriptId()
if script_id is not None:
script = self.getParent()._getOb(script_id)
if script is not None:
LOG("zwj: Executing after script %s for %s"%(script_id,self.getId()),WARNING,"in Transition.py.")
#script(**form_kw) ### zwj: call the name of script to execute itself
script.execute(sci)
def _executeBeforeScript(self, document, workflow, state_object, form_kw=None):
"""
Execute pre transition script.
"""
former_status = state_object.getId()
old_sdef = state_object
new_sdef = document.unrestrictedTraverse(self.getDestination())
kwargs = form_kw
sci = StateChangeInfo(
document, workflow, former_status, self, old_sdef, new_sdef, kwargs)
if form_kw is None:
form_kw = {}
script_id = self.getBeforeScriptId()
if script_id is not None:
script = self.getParent()._getOb(script_id)
#script = getattr(document, script_id)
#script(**form_kw)
if script is not None:
LOG("zwj: Executing before script %s for %s"%(script_id,self.getId()),WARNING,"in Transition.py.")
#script(**form_kw) ### zwj: call the name of script to execute itself
script.execute(sci)
def _checkPermission(self, document): def _checkPermission(self, document):
""" """
Check if transition is allowed. Check if transition is allowed.
......
...@@ -82,7 +82,9 @@ class Workflow(XMLObject): ...@@ -82,7 +82,9 @@ class Workflow(XMLObject):
object = self.getStateChangeInformation(document, self.getSourceValue()) object = self.getStateChangeInformation(document, self.getSourceValue())
# Initialize workflow history # Initialize workflow history
status_dict = {state_bc_id: self.getSource()} status_dict = {state_bc_id: document.unrestrictedTraverse(self.getSource()).getId()}
status_dict['time'] = self.getDateTime()
status_dict['action'] = None
variable_list = self.contentValues(portal_type='Variable') variable_list = self.contentValues(portal_type='Variable')
for variable in variable_list: for variable in variable_list:
status_dict[variable.getTitle()] = variable.getInitialValue(object=object) status_dict[variable.getTitle()] = variable.getInitialValue(object=object)
...@@ -94,7 +96,8 @@ class Workflow(XMLObject): ...@@ -94,7 +96,8 @@ class Workflow(XMLObject):
""" """
Generate a key used in the workflow history. Generate a key used in the workflow history.
""" """
return self.getRelativeUrl() history_key = self.unrestrictedTraverse(self.getRelativeUrl()).getId()
return history_key
def _updateWorkflowHistory(self, document, status_dict): def _updateWorkflowHistory(self, document, status_dict):
""" """
...@@ -112,7 +115,8 @@ class Workflow(XMLObject): ...@@ -112,7 +115,8 @@ class Workflow(XMLObject):
document.workflow_history[workflow_key] = () document.workflow_history[workflow_key] = ()
# Update history # Update history
document.workflow_history[workflow_key] += (status_dict, ) status_dict['time'] = self.getDateTime()
document.workflow_history[workflow_key] += (status_dict,)
# XXX this _p_changed marks the document modified, but the # XXX this _p_changed marks the document modified, but the
# only the PersistentMapping is modified # only the PersistentMapping is modified
document._p_changed = 1 document._p_changed = 1
......
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