1
2
3
4
5
6
7
8
9
10
11 import os, md5
12 from Globals import InitializeClass, DevelopmentMode
13 from AccessControl import getSecurityManager
14 from Products.ZenRelations.RelSchema import *
15 from Products.ZenModel.ZenModelRM import ZenModelRM
16 from Products.ZenMessaging.audit import audit
17 from Products.ZenModel.ZenossSecurity import *
18 from Products.ZenWidgets import messaging
19
20 from Portlet import Portlet
21
22 getuid = lambda:md5.md5(os.urandom(10)).hexdigest()[:8]
23
25
35
37 """
38 A registry for portlet source and metadata. Provides access functions and
39 handles portlet permissions.
40 """
41
42 portal_type = meta_type = 'PortletManager'
43
44 _relations = (
45 ("portlets", ToManyCont(ToOne, "Products.ZenWidgets.Portlet",
46 "portletManager")),
47 )
48
56
59 """
60 Registers a new source file and creates an associated Portlet to store
61 the metadata and provide access methods.
62 """
63 p = self.find(id, sourcepath)
64 if p:
65 old_values = (p.sourcepath, p.id, p.title, p.description, p.preview, p.height, p.permission)
66 new_values = (sourcepath, id, title, description, preview, height, permission)
67 if old_values == new_values:
68
69 return
70 self.unregister_portlet(p.id)
71 p = Portlet(sourcepath, id, title, description, preview, height, permission)
72 self.portlets._setObject(id, p)
73
76
87
88 - def find(self, id='', sourcepath=''):
89 """
90 Look for a registered portlet with an id or source path.
91 """
92 for portlet in self.portlets():
93 if portlet.id==id or portlet.sourcepath==sourcepath: return portlet
94 return None
95
97 """
98 Reread the source files for all portlets.
99 """
100 for portlet in self.portlets():
101 portlet._read_source()
102
104 """
105 Return the source of the portlets permitted to this user as a
106 javascript file.
107 """
108 srcs = [x.get_source(DevelopmentMode) for x in self.get_portlets()]
109 srcs.append('YAHOO.register("portletsource", YAHOO.zenoss.portlet, {})')
110 if REQUEST:
111 REQUEST.response.headers['Content-Type'] = 'text/javascript'
112 return '\n'.join(srcs)
113
131
132
133 InitializeClass(PortletManager)
134