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 @@
# Expression patch
from Products.CMFCore.Expression import Expression
from Products.DCWorkflow.Expression import createExprContext
from Acquisition import aq_inner
from Acquisition import aq_parent
from Products.PageTemplates.Expressions import getEngine
......@@ -27,8 +28,9 @@ def Expression_hash(self):
Expression.__hash__ = Expression_hash
def Expression_createExprContext(sci):
# compatibility according to the new structure of workflow:
# deploy script getter to return a list of script.
def createExprContext(sci):
'''
An expression context provides names for TALES expressions.
'''
......@@ -54,21 +56,3 @@ def Expression_createExprContext(sci):
'scripts': scripts,
}
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
from Products.ERP5Type import Permissions, PropertySheet, Globals
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
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.Workflow import addWorkflowFactory
from Products.ERP5Workflow.Document.Transition import TRIGGER_WORKFLOW_METHOD
......@@ -152,7 +152,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), XMLObject):
value = status[name]
# Not set yet. Use a default.
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)
else:
value = vdef.default_value
......@@ -354,7 +354,7 @@ class InteractionWorkflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sci = StateChangeInfo(
ob, self, former_status, tdef,
None, None, None)
econtext = Expression_createExprContext(sci)
econtext = createExprContext(sci)
value = expr(econtext)
status[id] = value
......
......@@ -34,14 +34,12 @@ from copy import deepcopy
from Products.CMFCore.Expression import Expression
from Products.CMFCore.utils import getToolByName
from Products.DCWorkflow.DCWorkflow import ObjectDeleted, ObjectMoved
from Products.DCWorkflow.Expression import StateChangeInfo
from Products.DCWorkflow.Guard import Guard
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Accessor.Base import _evaluateTales
from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.id_as_reference import IdAsReferenceMixin
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.Utils import convertToUpperCase, convertToMixedCase
from Products.ERP5Type.XMLObject import XMLObject
......
......@@ -52,7 +52,7 @@ from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition as DCWorkflow
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Globals import PersistentMapping
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,\
WORKLIST_METADATA_KEY
from Products.ERP5Type.Utils import UpperCase, convertToMixedCase
......@@ -107,7 +107,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
status_dict = {state_var: state_id}
variable_list = self.objectValues(portal_type='Variable')
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:
if variable.for_status == 0:
......@@ -393,7 +393,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for key in worklist_definition.getVarMatchKeys():
var = worklist_definition.getVarMatch(key)
if isinstance(var, Expression):
evaluated_value = var(Expression_createExprContext(StateChangeInfo(portal,
evaluated_value = var(createExprContext(StateChangeInfo(portal,
self, kwargs=info.__dict__.copy())))
if isinstance(evaluated_value, (str, int, long)):
evaluated_value = [str(evaluated_value)]
......@@ -471,7 +471,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
value = status_dict[name]
# Not set yet. Use a default.
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)
value = expr(ec)
else:
......@@ -685,7 +685,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
sci = StateChangeInfo(
document, self, former_status, tdef,
old_sdef, new_sdef, kwargs)
econtext = Expression_createExprContext(sci)
econtext = createExprContext(sci)
expr = Expression(expr)
value = expr(econtext)
if value is None: value = ''
......
......@@ -35,7 +35,7 @@ from Persistence import PersistentMapping
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet
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.DCWorkflow.Expression import Expression, StateChangeInfo
from Products.DCWorkflow.Guard import Guard
......@@ -231,7 +231,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
if isinstance(values, Expression):
wf = self.getParent()
portal = wf._getPortalRoot()
context = Expression_createExprContext(StateChangeInfo(portal, wf))
context = createExprContext(StateChangeInfo(portal, wf))
criteria[key] = values(context)
else:
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