Commit 79b666bd authored by wenjie.zheng's avatar wenjie.zheng

patches/Expression.py: add ERP5Workflow compatibility.

parent d96144a9
...@@ -15,8 +15,65 @@ ...@@ -15,8 +15,65 @@
# Expression patch # Expression patch
from Products.CMFCore.Expression import Expression 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): def Expression_hash(self):
return hash(self.text) return hash(self.text)
Expression.__hash__ = Expression_hash 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
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