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

ERP5Workflow: wip

parent 6c784645
...@@ -109,12 +109,7 @@ class PythonScript(XMLObject, ZopePythonScript): ...@@ -109,12 +109,7 @@ class PythonScript(XMLObject, ZopePythonScript):
""" """
override to call ZopePythonScript methods to force compiling code override to call ZopePythonScript methods to force compiling code
""" """
if value is None:
value = ''
self._baseSetParameterSignature(value) self._baseSetParameterSignature(value)
if self._params is None or '':
### zwj: avoid NoneType parameters from generating in ZHtml edit page
delattr(self, "_params")
self._compile() self._compile()
def _setProxyRoleList(self, value): def _setProxyRoleList(self, value):
...@@ -128,9 +123,6 @@ class PythonScript(XMLObject, ZopePythonScript): ...@@ -128,9 +123,6 @@ class PythonScript(XMLObject, ZopePythonScript):
def edit(self, **kw): def edit(self, **kw):
XMLObject.edit(self, **kw) XMLObject.edit(self, **kw)
# We need to take __setstate__ from ZopePythonScript in order to # We need to take __setstate__ from ZopePythonScript in order to
# generate _v_ft attributes which is necessary to run the script # generate _v_ft attributes which is necessary to run the script
__setstate__ = ZopePythonScript.__setstate__ __setstate__ = ZopePythonScript.__setstate__
InitializeClass(PythonScript)
\ No newline at end of file
...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo ...@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Accessor.Base import _evaluateTales from Products.ERP5Type.Accessor.Base import _evaluateTales
from Products.DCWorkflow.Expression import StateChangeInfo
from zLOG import LOG, ERROR, DEBUG, WARNING from zLOG import LOG, ERROR, DEBUG, WARNING
class Transition(XMLObject): class Transition(XMLObject):
...@@ -64,22 +65,23 @@ class Transition(XMLObject): ...@@ -64,22 +65,23 @@ class Transition(XMLObject):
if form_kw is None: if form_kw is None:
form_kw = {} form_kw = {}
workflow = self.getParentValue() 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 # Call the before script
self._executeBeforeScript(document, form_kw=form_kw) self._executeBeforeScript(document, workflow, state_object, form_kw=form_kw)
# Modify the state # Modify the state
self._changeState(document) self._changeState(document)
### zwj: update Role mapping, also in Workflow, initialiseDocument() ### zwj: update Role mapping, also in Workflow, initialiseDocument()
self.getParent().updateRoleMappingsFor(document) self.getParent().updateRoleMappingsFor(document)
# Get variable values
status_dict = workflow.getCurrentStatusDict(document)
status_dict['undo'] = 0 status_dict['undo'] = 0
# Modify workflow history # Modify workflow history
state_bc_id = workflow.getStateBaseCategory()
status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0] status_dict[state_bc_id] = document.getCategoryMembershipList(state_bc_id)[0]
state_object = document.unrestrictedTraverse(status_dict[state_bc_id])
object = workflow.getStateChangeInformation(document, state_object, transition=self) object = workflow.getStateChangeInformation(document, state_object, transition=self)
# Update all variables # Update all variables
...@@ -102,7 +104,7 @@ class Transition(XMLObject): ...@@ -102,7 +104,7 @@ class Transition(XMLObject):
workflow._updateWorkflowHistory(document, status_dict) workflow._updateWorkflowHistory(document, status_dict)
# Call the after script # Call the after script
self._executeAfterScript(document, form_kw=form_kw) self._executeAfterScript(document, workflow, state_object, form_kw=form_kw)
def _changeState(self, document): def _changeState(self, document):
""" """
...@@ -114,25 +116,36 @@ class Transition(XMLObject): ...@@ -114,25 +116,36 @@ 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, form_kw=None): def _executeAfterScript(self, document, workflow, state_object, form_kw=None):
""" """
Execute post transition script. 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: if form_kw is None:
form_kw = {} form_kw = {}
script_id = self.getAfterScriptId() script_id = self.getAfterScriptId()
if script_id is not None: if script_id is not None:
script = self.getParent()._getOb(script_id) script = self.getParent()._getOb(script_id)
if script is not None: if script is not None:
LOG("zwj: Executing after script %s for %s"%(script_id,self.getId()),WARNING,"in Transition.py.") 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(**form_kw) ### zwj: call the name of script to execute itself
script.execute() script.execute(sci)
def _executeBeforeScript(self, document, form_kw=None): def _executeBeforeScript(self, document, workflow, state_object, form_kw=None):
""" """
Execute pre transition script. 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: if form_kw is None:
form_kw = {} form_kw = {}
script_id = self.getBeforeScriptId() script_id = self.getBeforeScriptId()
...@@ -143,7 +156,8 @@ class Transition(XMLObject): ...@@ -143,7 +156,8 @@ class Transition(XMLObject):
if script is not None: if script is not None:
LOG("zwj: Executing before script %s for %s"%(script_id,self.getId()),WARNING,"in Transition.py.") 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(**form_kw) ### zwj: call the name of script to execute itself
script.execute() script.execute(sci)
def _checkPermission(self, document): def _checkPermission(self, document):
""" """
......
...@@ -247,5 +247,6 @@ class Workflow(XMLObject): ...@@ -247,5 +247,6 @@ class Workflow(XMLObject):
out.append('%s -> %s [label="%s"];' % (k[0], k[1], out.append('%s -> %s [label="%s"];' % (k[0], k[1],
',\\n'.join(v))) ',\\n'.join(v)))
out.append('}') out.append('}')
return '\n'.join(out) return '\n'.join(out)
...@@ -52,13 +52,15 @@ class WorkflowScript(PythonScript): ...@@ -52,13 +52,15 @@ class WorkflowScript(PythonScript):
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
PythonScript.__init__(self, *args, **kw) PythonScript.__init__(self, *args, **kw)
LOG('zwj: Init _params = %s'%self._params, WARNING, ' in WorkflowScript.py')
### zwj: override __call__ to access view page instead of executing script
def __call__(self): def __call__(self):
r_url = self.REQUEST.get('URL') r_url = self.REQUEST.get('URL')
return self.REQUEST.RESPONSE.redirect(r_url+'/view') return self.REQUEST.RESPONSE.redirect(r_url+'/view')
execute = PythonScript.__call__ execute = PythonScript.__call__
# We need to take __setstate__ from PythonScript in order to
# generate _v_ft attributes which is necessary to run the script
__setstate__ = PythonScript.__setstate__
InitializeClass(WorkflowScript) InitializeClass(WorkflowScript)
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