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

patches/Expression.py: cleanup this file, rename method createExprContext and...

patches/Expression.py: cleanup this file, rename method createExprContext and redeploy this method in workflow.
parent a01a7866
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# Expression patch # Expression patch
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
from Products.DCWorkflow.Expression import createExprContext
from Acquisition import aq_inner from Acquisition import aq_inner
from Acquisition import aq_parent from Acquisition import aq_parent
from Products.PageTemplates.Expressions import getEngine from Products.PageTemplates.Expressions import getEngine
...@@ -27,8 +28,9 @@ def Expression_hash(self): ...@@ -27,8 +28,9 @@ def Expression_hash(self):
Expression.__hash__ = Expression_hash Expression.__hash__ = Expression_hash
# compatibility according to the new structure of workflow:
def Expression_createExprContext(sci): # deploy script getter to return a list of script.
def createExprContext(sci):
''' '''
An expression context provides names for TALES expressions. An expression context provides names for TALES expressions.
''' '''
...@@ -54,21 +56,3 @@ def Expression_createExprContext(sci): ...@@ -54,21 +56,3 @@ def Expression_createExprContext(sci):
'scripts': scripts, 'scripts': scripts,
} }
return getEngine().getContext(data) return getEngine().getContext(data)
Expression.createExprContext = Expression_createExprContext
def StateChangeInfo_getHistory(self):
wf = self.workflow
if getattr(wf, 'getTypeInfo'):
tool = wf.getPortalObject().portal_workflow
wf_id = wf.getReference()
else:
tool = aq_parent(aq_inner(wf))
wf_id = wf.id
h = tool.getHistoryOf(wf_id, self.object)
if h:
return map(lambda dict: dict.copy(), h) # Don't allow mutation
else:
return ()
StateChangeInfo.getHistory = StateChangeInfo_getHistory
...@@ -39,7 +39,7 @@ from Products.DCWorkflow.Expression import StateChangeInfo ...@@ -39,7 +39,7 @@ from Products.DCWorkflow.Expression import StateChangeInfo
from Products.ERP5Type import Permissions, PropertySheet, Globals from Products.ERP5Type import Permissions, PropertySheet, Globals
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.patches.Expression import Expression_createExprContext from Products.ERP5Type.patches.Expression import createExprContext
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Workflow import addWorkflowFactory from Products.ERP5Type.Workflow import addWorkflowFactory
from Products.ERP5Workflow.Document.Transition import TRIGGER_WORKFLOW_METHOD from Products.ERP5Workflow.Document.Transition import TRIGGER_WORKFLOW_METHOD
...@@ -152,7 +152,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -152,7 +152,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), XMLObject):
value = status[name] value = status[name]
# Not set yet. Use a default. # Not set yet. Use a default.
elif vdef.default_expr is not None: elif vdef.default_expr is not None:
ec = Expression_createExprContext(StateChangeInfo(ob, self, status)) ec = createExprContext(StateChangeInfo(ob, self, status))
value = vdef.default_expr(ec) value = vdef.default_expr(ec)
else: else:
value = vdef.default_value value = vdef.default_value
...@@ -354,7 +354,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -354,7 +354,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sci = StateChangeInfo( sci = StateChangeInfo(
ob, self, former_status, tdef, ob, self, former_status, tdef,
None, None, None) None, None, None)
econtext = Expression_createExprContext(sci) econtext = createExprContext(sci)
value = expr(econtext) value = expr(econtext)
status[id] = value status[id] = value
......
...@@ -34,14 +34,12 @@ from copy import deepcopy ...@@ -34,14 +34,12 @@ from copy import deepcopy
from Products.CMFCore.Expression import Expression from Products.CMFCore.Expression import Expression
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.DCWorkflow import ObjectDeleted, ObjectMoved from Products.DCWorkflow.DCWorkflow import ObjectDeleted, ObjectMoved
from Products.DCWorkflow.Expression import StateChangeInfo
from Products.DCWorkflow.Guard import Guard from Products.DCWorkflow.Guard import Guard
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Accessor.Base import _evaluateTales from Products.ERP5Type.Accessor.Base import _evaluateTales
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.patches.DCWorkflow import ValidationFailed from Products.ERP5Type.patches.DCWorkflow import ValidationFailed
from Products.ERP5Type.patches.Expression import Expression_createExprContext
from Products.ERP5Type.patches.WorkflowTool import WorkflowHistoryList from Products.ERP5Type.patches.WorkflowTool import WorkflowHistoryList
from Products.ERP5Type.Utils import convertToUpperCase, convertToMixedCase from Products.ERP5Type.Utils import convertToUpperCase, convertToMixedCase
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
......
...@@ -52,7 +52,7 @@ from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition as DCWorkflow ...@@ -52,7 +52,7 @@ from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition as DCWorkflow
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.patches.Expression import Expression_createExprContext from Products.ERP5Type.patches.Expression import createExprContext
from Products.ERP5Type.patches.WorkflowTool import SECURITY_PARAMETER_ID,\ from Products.ERP5Type.patches.WorkflowTool import SECURITY_PARAMETER_ID,\
WORKLIST_METADATA_KEY WORKLIST_METADATA_KEY
from Products.ERP5Type.Utils import UpperCase, convertToMixedCase from Products.ERP5Type.Utils import UpperCase, convertToMixedCase
...@@ -107,7 +107,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -107,7 +107,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
status_dict = {state_var: state_id} status_dict = {state_var: state_id}
variable_list = self.objectValues(portal_type='Variable') variable_list = self.objectValues(portal_type='Variable')
former_status = self._getOb(status_dict[state_var], None) former_status = self._getOb(status_dict[state_var], None)
ec = Expression_createExprContext(StateChangeInfo(document, self, former_status)) ec = createExprContext(StateChangeInfo(document, self, former_status))
for variable in variable_list: for variable in variable_list:
if variable.for_status == 0: if variable.for_status == 0:
...@@ -393,7 +393,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -393,7 +393,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for key in worklist_definition.getVarMatchKeys(): for key in worklist_definition.getVarMatchKeys():
var = worklist_definition.getVarMatch(key) var = worklist_definition.getVarMatch(key)
if isinstance(var, Expression): if isinstance(var, Expression):
evaluated_value = var(Expression_createExprContext(StateChangeInfo(portal, evaluated_value = var(createExprContext(StateChangeInfo(portal,
self, kwargs=info.__dict__.copy()))) self, kwargs=info.__dict__.copy())))
if isinstance(evaluated_value, (str, int, long)): if isinstance(evaluated_value, (str, int, long)):
evaluated_value = [str(evaluated_value)] evaluated_value = [str(evaluated_value)]
...@@ -471,7 +471,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -471,7 +471,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
value = status_dict[name] value = status_dict[name]
# Not set yet. Use a default. # Not set yet. Use a default.
if vdef.default_expr is not None: if vdef.default_expr is not None:
ec = Expression_createExprContext(StateChangeInfo(ob, self, former_status)) ec = createExprContext(StateChangeInfo(ob, self, former_status))
expr = Expression(vdef.default_expr) expr = Expression(vdef.default_expr)
value = expr(ec) value = expr(ec)
else: else:
...@@ -685,7 +685,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject): ...@@ -685,7 +685,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sci = StateChangeInfo( sci = StateChangeInfo(
document, self, former_status, tdef, document, self, former_status, tdef,
old_sdef, new_sdef, kwargs) old_sdef, new_sdef, kwargs)
econtext = Expression_createExprContext(sci) econtext = createExprContext(sci)
expr = Expression(expr) expr = Expression(expr)
value = expr(econtext) value = expr(econtext)
if value is None: value = '' if value is None: value = ''
......
...@@ -35,7 +35,7 @@ from Persistence import PersistentMapping ...@@ -35,7 +35,7 @@ from Persistence import PersistentMapping
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
from Products.ERP5Type.patches.Expression import Expression_createExprContext from Products.ERP5Type.patches.Expression import createExprContext
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.DCWorkflow.Expression import Expression, StateChangeInfo from Products.DCWorkflow.Expression import Expression, StateChangeInfo
from Products.DCWorkflow.Guard import Guard from Products.DCWorkflow.Guard import Guard
...@@ -231,7 +231,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -231,7 +231,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
if isinstance(values, Expression): if isinstance(values, Expression):
wf = self.getParent() wf = self.getParent()
portal = wf._getPortalRoot() portal = wf._getPortalRoot()
context = Expression_createExprContext(StateChangeInfo(portal, wf)) context = createExprContext(StateChangeInfo(portal, wf))
criteria[key] = values(context) criteria[key] = values(context)
else: else:
criteria[key] = [x % info for x in values] criteria[key] = [x % info for x in values]
......
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