vendor/CMFonFive/1.2.0

view fiveactionstool.py @ 1:d9180cd7b7c5

Eggify.
author sfermigier
date Thu, 15 Dec 2005 19:25:10 +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 14923 2005-07-22 15:47:32Z 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.publisher.browser.globalbrowsermenuservice import \
25 globalBrowserMenuService
26 from globalbrowsermenuservice import getMenu
27 from Products.Five import security
28 import zope.thread
30 class FiveActionsTool( UniqueObject, SimpleItem, ActionProviderBase ):
31 """ Links content to discussions.
32 """
34 __implements__ = (ActionProviderBase.__implements__)
36 id = 'portal_fiveactions'
37 meta_type = 'Five Actions Tool'
39 security = ClassSecurityInfo()
41 def getReqestURL(self):
42 return self.REQUEST.URL
44 security.declarePrivate('listActions')
45 def listActions(self, info=None, object=None):
46 """ List all the actions defined by a provider.
47 """
48 # Necessary to make the Request look like a Zope3 request
49 # XXX This can be removed when we no longer need Five 1.0 compatibility.
50 #self.REQUEST.getURL = self.getReqestURL
51 if object is None:
52 object = info.content
53 actions = []
54 for mid in globalBrowserMenuService._registry.keys():
55 menu = getMenu(mid, object, self.REQUEST)
56 for entry in menu:
57 # The action needs a unique name, so I'll build one
58 # from the object_id and the action url. That is sure
59 # to be unique.
60 action = str(entry['action'])
61 if object is None:
62 act_id = 'action_%s' % action
63 else:
64 act_id = 'action_%s_%s' % (object.getId(), action)
66 if entry['filter'] is None:
67 filter = None
68 else:
69 filter = Expression(text=str(entry['filter']))
71 act = ActionInformation(id=act_id,
72 title=str(entry['title']),
73 action=Expression(text='string:%s' % action),
74 condition=filter,
75 category=str(mid),
76 visible=1)
77 actions.append(act)
78 return actions or ()
81 InitializeClass( FiveActionsTool )