1
2
3
4
5
6
7
8
9
10
11
12
13
14 from string import Template
15
16 from Products.ZenModel.ZenossSecurity import *
17 from os.path import basename, exists
18 from Products.ZenRelations.RelSchema import *
19 from Products.ZenModel.ZenModelRM import ZenModelRM
20 from Globals import InitializeClass
21 from Products.ZenUtils.Utils import zenPath
22
24 """
25 Add a portlet.
26 """
27 pass
28
30 """
31 A wrapper for a portlet javascript source file that can include metadata
32 such as a name, a title, a description and permissions.
33
34 Portlets should not be instantiated directly. They should only be created
35 by a PortletManager object.
36 """
37 source = ''
38
39 portal_type = meta_type = 'Portlet'
40
41 _relations = (
42 ("portletManager", ToOne(
43 ToManyCont, "Products.ZenWidgets.PortletManager", "portlets")),
44 )
45
46 _properties = (
47 {'id':'title','type':'string','mode':'w'},
48 {'id':'description', 'type':'string', 'mode':'w'},
49 {'id':'permission', 'type':'string', 'mode':'w'},
50 {'id':'sourcepath', 'type':'string', 'mode':'w'},
51 {'id':'preview', 'type':'string', 'mode':'w'},
52 {'id':'height', 'type':'int', 'mode':'w'},
53 )
54
55
56 - def __init__(self, sourcepath, id='', title='', description='',
57 preview='', height=200, permission=ZEN_COMMON):
68
71
74
76 try:
77 f = file(self._getSourcePath())
78 except IOError, e:
79 return
80 else:
81 tvars = {'portletId': self.id,
82 'portletTitle': self.title,
83 'portletHeight': self.height}
84 self.source = Template(f.read()).safe_substitute(tvars)
85 f.close()
86
88 """
89 Override the default, which doesn't account for things on zport
90 """
91 return ('', 'zport') + super(Portlet, self).getPrimaryPath(fromNode)
92
94 if debug_mode: self._read_source()
95 src = []
96 src.append(self.source)
97 src.append("YAHOO.zenoss.portlet.register_portlet('%s', '%s');" % (
98 self.id, self.title))
99 return '\n'.join(src)
100
101 InitializeClass(Portlet)
102