diff --git a/product/ERP5Type/patches/Expression.py b/product/ERP5Type/patches/Expression.py index ec2b84e528801d3cd4cda889cf9b1aa30e9439a9..70b02c503ffb4d5ecc7b4db119a1222bdc021c07 100644 --- a/product/ERP5Type/patches/Expression.py +++ b/product/ERP5Type/patches/Expression.py @@ -15,8 +15,65 @@ # Expression patch from Products.CMFCore.Expression import Expression +from Acquisition import aq_inner +from Acquisition import aq_parent +from Products.PageTemplates.Expressions import getEngine +from Products.PageTemplates.Expressions import SecureModuleImporter +from AccessControl.SecurityManagement import getSecurityManager +from Products.DCWorkflow.Expression import StateChangeInfo def Expression_hash(self): return hash(self.text) - Expression.__hash__ = Expression_hash + + +def Expression_createExprContext(sci): + ''' + An expression context provides names for TALES expressions. + ''' + ob = sci.object + wf = sci.workflow + if wf.getTypeInfo().getId() == 'Workflow': + scripts = wf.objectValues(portal_type='Workflow Script') + else: + scripts = wf.scripts + container = aq_parent(aq_inner(ob)) + data = { + 'here': ob, + 'object': ob, + 'container': container, + 'folder': container, + 'nothing': None, + 'root': ob.getPhysicalRoot(), + 'request': getattr( ob, 'REQUEST', None ), + 'modules': SecureModuleImporter, + 'user': getSecurityManager().getUser(), + 'state_change': sci, + 'transition': sci.transition, + 'status': sci.status, + 'kwargs': sci.kwargs, + 'workflow': wf, + 'scripts': scripts, + } + return getEngine().getContext(data) + +Expression.createExprContext = Expression_createExprContext + +def StateChanceInfo_getHistory(self): + wf = self.workflow + #raise NotImplementedError (wf) + #raise NotImplementedError(wf.getTypeInfo()) + if getattr(wf, 'getTypeInfo'): + tool = wf.getPortalObject().portal_workflow + wf_id = wf.getId() + 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 = StateChanceInfo_getHistory +