############################################################################## # # Copyright (c) 2005 CMFonFive Contributors. All rights reserved. # # This software is distributed under the terms of the Zope Public # License (ZPL) v2.1. See COPYING.txt for more information. # ########################################################################### """ Five actions tool. $Id$ """ from AccessControl import ClassSecurityInfo from Acquisition import aq_base from Globals import InitializeClass from OFS.SimpleItem import SimpleItem from Products.CMFCore.ActionInformation import ActionInformation from Products.CMFCore.ActionProviderBase import ActionProviderBase from Products.CMFCore.Expression import Expression from Products.CMFCore.utils import UniqueObject from zope.app import zapi from zope.app.publisher.interfaces.browser import IBrowserMenu from zope.app.publisher.browser.menu import getMenu def _listMenuIds(): return [id for id, utility in zapi.getUtilitiesFor(IBrowserMenu)] from Products.Five import security import zope.thread class FiveActionsTool( UniqueObject, SimpleItem, ActionProviderBase ): """ Links content to discussions. """ __implements__ = (ActionProviderBase.__implements__) id = 'portal_fiveactions' meta_type = 'Five Actions Tool' security = ClassSecurityInfo() def getReqestURL(self): return self.REQUEST.URL security.declarePrivate('listActions') def listActions(self, info=None, object=None): """ List all the actions defined by a provider. """ # Necessary to make the Request look like a Zope3 request # XXX This can be removed when we no longer need Five 1.0 compatibility. #self.REQUEST.getURL = self.getReqestURL if object is None: object = info.content actions = [] for menu_id in _listMenuIds(): for entry in getMenu(menu_id, object, self.REQUEST): # The action needs a unique name, so I'll build one # from the object_id and the action url. That is sure # to be unique. action = str(entry['action']) if object is None: act_id = 'action_%s' % action else: act_id = 'action_%s_%s' % (object.getId(), action) if entry.get('filter') is None: filter = None else: filter = Expression(text=str(entry['filter'])) title = entry['title'] # Having bits of unicode here can make rendering very confused. if isinstance(title, unicode): title = str(title) act = ActionInformation(id=act_id, title=title, action=Expression(text='string:%s' % action), condition=filter, category=str(menu_id), visible=1) actions.append(act) return tuple(actions) InitializeClass( FiveActionsTool )