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