Commit b022bd72 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* add getActionListFor() that does not filter (cf. getFilteredActionListFor() filters).

* revert r29647 and use getActionListFor() and call test() for its result in getDefaultViewFor(), so that createExpressionContext() is only called once.
* use getActionListFor() and call test() for its result in listFilteredActionsFor(), so that createExpressionContext() is only called once..


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29650 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 68786fdf
......@@ -497,15 +497,16 @@ class ERP5TypeInformation(XMLObject,
"""
ec = createExpressionContext(ob)
best_action = (), None
for action in self.getFilteredActionListFor(ob):
for action in self.getActionListFor(ob):
if action.getReference() == view:
break
if action.test(ec):
break
else:
# In case that "view" (or "list") action is not present or not allowed,
# find something that's allowed (of the same category, if possible).
index = (action.getActionType().endswith('_' + view),
-action.getFloatIndex())
if best_action[0] < index:
if best_action[0] < index and action.test(ec):
best_action = index, action
else:
action = best_action[1]
......@@ -519,6 +520,11 @@ class ERP5TypeInformation(XMLObject,
__traceback_info__ = self.getId(), target
return ob.restrictedTraverse(target)
security.declarePrivate('getActionListFor')
def getActionListFor(self, ob=None):
"""Return all actions of the object"""
return self.getActionInformationList()
security.declarePrivate('getFilteredActionListFor')
def getFilteredActionListFor(self, ob=None):
"""Return all actions applicable to the object"""
......
......@@ -42,6 +42,15 @@ class TypesTool(BaseTool, CMFCore_TypesTool.TypesTool):
zope.interface.implements(interfaces.IActionProvider)
security.declarePrivate('getActionListFor')
def getActionListFor(self, ob=None):
"""Return all actions of the object"""
if ob is not None:
type_info = self.getTypeInfo(ob)
if type_info is not None:
return type_info.getActionListFor(ob)
return ()
security.declarePrivate('getFilteredActionListFor')
def getFilteredActionListFor(self, ob=None):
"""Return all actions applicable to the object"""
......
......@@ -53,6 +53,9 @@ class IAction(Interface):
class IActionProvider(Interface):
"""
"""
def getActionListFor(ob):
"""Return all actions of the object"""
def getFilteredActionListFor(ob):
"""Return all actions applicable to the object
"""
......@@ -36,12 +36,13 @@ def listFilteredActionsFor(self, object=None):
provider = getattr(self, provider_name)
if providedBy(provider):
actions.extend( provider.listActionInfos(object=object) )
elif hasattr(provider, 'getFilteredActionListFor'):
elif hasattr(provider, 'getActionListFor'):
from Products.ERP5Type.Utils import createExpressionContext
ec = createExpressionContext(object)
actions += sorted(
(action.getActionInfo(ec)
for action in provider.getFilteredActionListFor(object)),
for action in provider.getActionListFor(object)
if action.test(ec)),
key=lambda x: x['priority'])
else:
# for Action Providers written for CMF versions before 1.5
......
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