Commit 7e6420dd authored by wenjie.zheng's avatar wenjie.zheng

Workflow.py: remove non necessary code in notifyCreated; fix...

Workflow.py: remove non necessary code in notifyCreated; fix _executeTransition when non transition pass to it as a parameter.
parent 904139f8
...@@ -95,32 +95,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -95,32 +95,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
) )
def notifyCreated(self, document): def notifyCreated(self, document):
"""
Set initial state on the Document
"""
state_var = self.getStateVariable()
object = self.getStateChangeInformation(document, self.getSourceValue())
# Initialize workflow history
state_id = self.getSourceValue().getReference()
status_dict = {state_var: state_id}
variable_list = self.objectValues(portal_type='Variable')
former_status = self._getOb(status_dict[state_var], None)
ec = createExprContext(StateChangeInfo(document, self, former_status))
for variable in variable_list: """Notifies this workflow after an object has been created and added.
if variable.for_status == 0: """
continue try:
if variable.default_expr is not None: self._changeStateOf(document, None)
expr = Expression(variable.default_expr) except ( ObjectDeleted, ObjectMoved ):
value = expr(ec) # Swallow.
else: pass
value = variable.getInitialValue(object=object)
if value is None: value = ''
status_dict[variable.getReference()] = value
self._updateWorkflowHistory(document, status_dict)
self.updateRoleMappingsFor(document)
initializeDocument = notifyCreated initializeDocument = notifyCreated
...@@ -613,7 +595,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -613,7 +595,8 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if tdef is None: if tdef is None:
new_sdef = self.getSourceValue() new_sdef = self.getSourceValue()
if not new_state: new_state = new_sdef.getReference()
if not new_sdef:
return return
former_status = {} former_status = {}
else: else:
...@@ -654,6 +637,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -654,6 +637,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if state_values is None: state_values = {} if state_values is None: state_values = {}
tdef_exprs = {} tdef_exprs = {}
transition_variable_list = []
if tdef is not None: if tdef is not None:
transition_variable_list = tdef.objectValues(portal_type='Transition Variable') transition_variable_list = tdef.objectValues(portal_type='Transition Variable')
for transition_variable in transition_variable_list: for transition_variable in transition_variable_list:
...@@ -719,22 +703,23 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -719,22 +703,23 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
self.updateRoleMappingsFor(document) self.updateRoleMappingsFor(document)
# Execute the "after" script. # Execute the "after" script.
script_id = getattr(tdef, 'getAfterScriptId')() if tdef is not None:
if script_id is not None: script_id = getattr(tdef, 'getAfterScriptId')()
kwargs = form_kw if script_id is not None:
# Script can be either script or workflow method kwargs = form_kw
if script_id in old_sdef.getDestinationIdList() and \ # Script can be either script or workflow method
self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD: if script_id in old_sdef.getDestinationIdList() and \
getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))() self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD:
else: getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))()
script = self._getOb(script_id)
# Pass lots of info to the script in a single parameter.
if script.getTypeInfo().getId() == 'Workflow Script':
sci = StateChangeInfo(
document, self, former_status, tdef, old_sdef, new_sdef, kwargs)
script.execute(sci) # May throw an exception.
else: else:
raise NotImplementedError ('Unsupported Script %s for state %s'%(script_id, old_sdef.getReference())) script = self._getOb(script_id)
# Pass lots of info to the script in a single parameter.
if script.getTypeInfo().getId() == 'Workflow Script':
sci = StateChangeInfo(
document, self, former_status, tdef, old_sdef, new_sdef, kwargs)
script.execute(sci) # May throw an exception.
else:
raise NotImplementedError ('Unsupported Script %s for state %s'%(script_id, old_sdef.getReference()))
# Return the new state object. # Return the new state object.
if moved_exc is not None: if moved_exc is not None:
# Propagate the notification that the object has moved. # Propagate the notification that the object has moved.
......
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