1
2
3
4
5
6
7
8
9
10
11 import logging
12 log = logging.getLogger('zen.Portlet')
13
14 from string import Template
15
16 from Products.ZenModel.ZenossSecurity import ZEN_COMMON
17 from os.path import basename, exists
18 from Products.ZenRelations.RelSchema import ToManyCont, ToOne
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 height = 200
39
40 portal_type = meta_type = 'Portlet'
41
42 _relations = (
43 ("portletManager", ToOne(
44 ToManyCont, "Products.ZenWidgets.PortletManager", "portlets")),
45 )
46
47 _properties = (
48 {'id':'title','type':'string','mode':'w'},
49 {'id':'description', 'type':'string', 'mode':'w'},
50 {'id':'permission', 'type':'string', 'mode':'w'},
51 {'id':'sourcepath', 'type':'string', 'mode':'w'},
52 {'id':'preview', 'type':'string', 'mode':'w'},
53 {'id':'height', 'type':'int', 'mode':'w'},
54 )
55
56
57 - def __init__(self, sourcepath, id='', title='', description='',
58 preview='', height=200, permission=ZEN_COMMON):
69
72
75
77 try:
78 path = self.sourcepath if exists(self.sourcepath) else self._getSourcePath()
79 f = file(path)
80 except IOError as ex:
81 log.error("Unable to load portlet from '%s': %s", path, ex)
82 return
83 else:
84 tvars = {'portletId': self.id,
85 'portletTitle': self.title,
86 'portletHeight': self.height}
87 self.source = Template(f.read()).safe_substitute(tvars)
88 f.close()
89
91 """
92 Override the default, which doesn't account for things on zport
93 """
94 return ('', 'zport') + super(Portlet, self).getPrimaryPath(fromNode)
95
97 if debug_mode: self._read_source()
98 src = []
99 src.append(self.source)
100 src.append("YAHOO.zenoss.portlet.register_portlet('%s', '%s');" % (
101 self.id, self.title))
102 return '\n'.join(src)
103
104 InitializeClass(Portlet)
105