vendor/CMFonFive/1.3.0

view fiveactionstool.py @ 1:4f3d7d6b5fee

Wrong version in version file.
author lregebro
date Fri, 06 Jan 2006 15:37:27 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2005 CMFonFive Contributors. All rights reserved.
4 #
5 # This software is distributed under the terms of the Zope Public
6 # License (ZPL) v2.1. See COPYING.txt for more information.
7 #
8 ###########################################################################
9 """ Five actions tool.
11 $Id: fiveactionstool.py 21741 2006-01-06 15:08:14Z regebro $
12 """
14 from AccessControl import ClassSecurityInfo
15 from Acquisition import aq_base
16 from Globals import InitializeClass
17 from OFS.SimpleItem import SimpleItem
19 from Products.CMFCore.ActionInformation import ActionInformation
20 from Products.CMFCore.ActionProviderBase import ActionProviderBase
21 from Products.CMFCore.Expression import Expression
22 from Products.CMFCore.utils import UniqueObject
24 from zope.app import zapi
25 from zope.app.publisher.interfaces.browser import IBrowserMenu
26 from zope.app.publisher.browser.menu import getMenu
28 def _listMenuIds():
29 return [id for id, utility in zapi.getUtilitiesFor(IBrowserMenu)]
31 from Products.Five import security
32 import zope.thread
34 class FiveActionsTool( UniqueObject, SimpleItem, ActionProviderBase ):
35 """ Links content to discussions.
36 """
38 __implements__ = (ActionProviderBase.__implements__)
40 id = 'portal_fiveactions'
41 meta_type = 'Five Actions Tool'
43 security = ClassSecurityInfo()
45 def getReqestURL(self):
46 return self.REQUEST.URL
48 security.declarePrivate('listActions')
49 def listActions(self, info=None, object=None):
50 """ List all the actions defined by a provider.
51 """
52 # Necessary to make the Request look like a Zope3 request
53 # XXX This can be removed when we no longer need Five 1.0 compatibility.
54 #self.REQUEST.getURL = self.getReqestURL
55 if object is None:
56 object = info.content
57 actions = []
59 for menu_id in _listMenuIds():
60 for entry in getMenu(menu_id, object, self.REQUEST):
61 # The action needs a unique name, so I'll build one
62 # from the object_id and the action url. That is sure
63 # to be unique.
64 action = str(entry['action'])
65 if object is None:
66 act_id = 'action_%s' % action
67 else:
68 act_id = 'action_%s_%s' % (object.getId(), action)
70 if entry.get('filter') is None:
71 filter = None
72 else:
73 filter = Expression(text=str(entry['filter']))
75 title = entry['title']
76 # Having bits of unicode here can make rendering very confused.
77 if isinstance(title, unicode):
78 title = str(title)
79 act = ActionInformation(id=act_id,
80 title=title,
81 action=Expression(text='string:%s' % action),
82 condition=filter,
83 category=str(menu_id),
84 visible=1)
85 actions.append(act)
87 return tuple(actions)
90 InitializeClass( FiveActionsTool )