Package ZenWidgets :: Module Portlet
[hide private]
[frames] | no frames]

Source Code for Module ZenWidgets.Portlet

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  from Products.ZenModel.ZenossSecurity import * 
15  from os.path import basename, exists 
16  from Products.ZenRelations.RelSchema import * 
17  from OFS.SimpleItem import SimpleItem 
18  from OFS.PropertyManager import PropertyManager 
19  from Products.ZenModel.ZenModelRM import ZenModelRM 
20  from Globals import InitializeClass, DevelopmentMode 
21   
22 -class PortletSourceNotFound(Exception): pass
23
24 -def manage_addPortlet(self, context, REQUEST=None):
25 """ 26 Add a portlet. 27 """ 28 pass
29
30 -class Portlet(ZenModelRM):
31 """ 32 A wrapper for a portlet javascript source file that can include metadata 33 such as a name, a title, a description and permissions. 34 35 Portlets should not be instantiated directly. They should only be created 36 by a PortletManager object. 37 """ 38 source = '' 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 ) 54
55 - def __init__(self, sourcepath, id='', title='', description='', 56 preview='', permission=ZEN_COMMON):
57 if not id: id = basename(sourcepath).split('.')[0] 58 self.id = id 59 ZenModelRM.__init__(self, id) 60 self.title = title 61 self.description = description 62 self.permission = permission 63 self.sourcepath = sourcepath 64 self.preview = preview 65 self._read_source()
66
67 - def check(self):
68 return exists(self.sourcepath)
69
70 - def _read_source(self):
71 try: 72 f = file(self.sourcepath) 73 except IOError, e: 74 raise PortletSourceNotFound, e 75 self.source = f.read() 76 f.close()
77
78 - def get_source(self, debug_mode=False):
79 if debug_mode: self._read_source() 80 src = [] 81 src.append(self.source) 82 src.append("YAHOO.zenoss.portlet.register_portlet('%s', '%s');" % ( 83 self.id, self.title)) 84 return '\n'.join(src)
85 86 InitializeClass(Portlet) 87