Commit b322a14c authored by Julien Muchembled's avatar Julien Muchembled

Use Utils.createExpressionContext instead of functions from CMF

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29264 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bff9e56b
......@@ -26,7 +26,7 @@ from AccessControl import ClassSecurityInfo, getSecurityManager
from Acquisition import aq_base, aq_inner, aq_parent
from Products.CMFCore.TypesTool import FactoryTypeInformation
from Products.CMFCore.Expression import createExprContext, Expression
from Products.CMFCore.Expression import Expression
from Products.CMFCore.exceptions import AccessControl_Unauthorized
from Products.CMFCore.utils import _checkPermission
from Products.ERP5Type import interfaces, Constraint, Permissions, PropertySheet
......@@ -55,22 +55,6 @@ from zLOG import LOG, ERROR
from Products.CMFCore.exceptions import zExceptions_Unauthorized
def getExprContext(context, ob=None):
portal = context.getPortalObject()
if ob is None:
folder = portal
else:
folder = aq_parent(ob)
# Search up the containment hierarchy until we find an
# object that claims it's a folder.
while folder is not None:
if getattr(aq_base(folder), 'isPrincipiaFolderish', 0):
break # found it.
else:
folder = aq_parent(folder)
return createExprContext(folder, portal, ob)
class LocalRoleAssignorMixIn(object):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
......@@ -155,7 +139,7 @@ class LocalRoleAssignorMixIn(object):
security.declarePrivate('getFilteredRoleListFor')
def getFilteredRoleListFor(self, ob=None):
"""Return all role generators applicable to the object."""
ec = getExprContext(self, ob)
ec = createExpressionContext(ob)
for role in self.getRoleInformationList():
if role.testCondition(ec):
yield role
......@@ -478,7 +462,7 @@ class ERP5TypeInformation(XMLObject,
security.declarePrivate('getFilteredActionListFor')
def getFilteredActionListFor(self, ob=None):
"""Return all actions applicable to the object"""
ec = getExprContext(self, ob)
ec = createExpressionContext(ob)
return (action for action in self.getActionInformationList()
if action.test(ec))
......
......@@ -1113,7 +1113,7 @@ def createExpressionContext(object, portal=None):
if portal is None and object is not None:
portal = object.getPortalObject()
if object is None or getattr(object, 'aq_base', None) is None:
if object is None or aq_base(object) is None:
folder = portal
else:
folder = object
......@@ -1161,6 +1161,7 @@ def createExpressionContext(object, portal=None):
'request': getattr( object, 'REQUEST', None ),
'modules': SecureModuleImporter,
'member': member,
'here': object,
}
return getEngine().getContext(data)
......
......@@ -30,8 +30,8 @@ def listFilteredActionsFor(self, object=None):
if IActionProvider.isImplementedBy(provider):
actions.extend( provider.listActionInfos(object=object) )
elif hasattr(provider, 'getFilteredActionListFor'):
from Products.ERP5Type.ERP5Type import getExprContext
ec = getExprContext(self, object)
from Products.ERP5Type.Utils import createExpressionContext
ec = createExpressionContext(object)
actions += sorted(
(action.getActionInfo(ec)
for action in provider.getFilteredActionListFor(object)),
......
......@@ -15,8 +15,8 @@
from warnings import warn
from Products.CMFCore.exceptions import AccessControl_Unauthorized, NotFound
from Products.CMFCore.utils import getActionContext
from Products.CMFCore.Expression import getExprContext
from Products.CMFCore import PortalContent
from Products.ERP5Type.Utils import createExpressionContext
from zLOG import LOG
......@@ -40,7 +40,7 @@ def CMFCoreUtils_getViewFor(obj, view='view'):
raise NotFound('Cannot find default view for %r' % obj.getPath())
context = getActionContext(obj)
ec = getExprContext(obj, obj)
ec = createExpressionContext(obj)
best_action = (), None
for action in ti.getFilteredActionListFor(obj):
if action.getReference() == view:
......
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