Back to index

plone3  3.1.7
fiveactionstool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Five actions tool.
00014 
00015 $Id: fiveactionstool.py 77186 2007-06-28 19:06:19Z yuppie $
00016 """
00017 
00018 from AccessControl import ClassSecurityInfo
00019 from Globals import InitializeClass
00020 from OFS.SimpleItem import SimpleItem
00021 from zope.app.publisher.browser.menu import getMenu
00022 from zope.app.publisher.interfaces.browser import IBrowserMenu
00023 from zope.component import getUtilitiesFor
00024 
00025 from Products.CMFCore.ActionInformation import ActionInformation
00026 from Products.CMFCore.ActionProviderBase import ActionProviderBase
00027 from Products.CMFCore.Expression import Expression
00028 from Products.CMFCore.utils import UniqueObject
00029 
00030 def _listMenuIds():
00031     return [id for id, utility in getUtilitiesFor(IBrowserMenu)]
00032 
00033 
00034 class FiveActionsTool( UniqueObject, SimpleItem, ActionProviderBase ):
00035 
00036     """ Links content to discussions.
00037     """
00038 
00039     __implements__ = (ActionProviderBase.__implements__)
00040 
00041     id = 'portal_fiveactions'
00042     meta_type = 'Five Actions Tool'
00043 
00044     security = ClassSecurityInfo()
00045 
00046     def getReqestURL(self):
00047         return self.REQUEST.URL
00048 
00049     security.declarePrivate('listActions')
00050     def listActions(self, info=None, object=None):
00051         """ List all the actions defined by a provider.
00052         """
00053         if object is None:
00054             if  info is None:
00055                 # There is no support for global actions
00056                 return ()
00057             else:
00058                 object = info.content
00059 
00060         actions = []
00061         for menu_id in _listMenuIds():
00062             for entry in getMenu(menu_id, object, self.REQUEST):
00063                 # The action needs a unique name, so I'll build one
00064                 # from the object_id and the action url. That is sure
00065                 # to be unique.
00066                 action = str(entry['action'])
00067                 if object is None:
00068                     act_id = 'action_%s' % action
00069                 else:
00070                     act_id = 'action_%s_%s' % (object.getId(), action)
00071 
00072                 if entry.get('filter') is None:
00073                     filter = None
00074                 else:
00075                     filter = Expression(text=str(entry['filter']))
00076 
00077                 title = entry['title']
00078                 # Having bits of unicode here can make rendering very confused,
00079                 # so we convert it to plain strings, but NOT if it is a 
00080                 # messageID. In Zope 3.2 there are two types of messages,
00081                 # Message and MessageID, where MessageID is depracated. We can 
00082                 # type-check for both but that provokes a deprecation warning, 
00083                 # so we check for the "domain" attribute instead. 
00084                 if not hasattr(title, 'domain'):
00085                     title = str(title)
00086                 act = ActionInformation(id=act_id,
00087                     title=title,
00088                     action=Expression(text='string:%s' % action),
00089                     condition=filter,
00090                     category=str(menu_id),
00091                     visible=1)
00092                 actions.append(act)
00093 
00094         return tuple(actions)
00095 
00096 InitializeClass( FiveActionsTool )