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

Source Code for Module Products.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 or (at your 
  8  # option) any later version as published by the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 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   
23 -def manage_addPortlet(self, context, REQUEST=None):
24 """ 25 Add a portlet. 26 """ 27 pass
28
29 -class Portlet(ZenModelRM):
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):
58 if not id: id = basename(sourcepath).split('.')[0] 59 self.id = id 60 ZenModelRM.__init__(self, id) 61 self.title = title 62 self.description = description 63 self.permission = permission 64 self.sourcepath = sourcepath 65 self.preview = preview 66 self.height = height 67 self._read_source()
68
69 - def _getSourcePath(self):
70 return zenPath(self.sourcepath)
71
72 - def check(self):
73 return exists(self._getSourcePath())
74
75 - def _read_source(self):
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
87 - def getPrimaryPath(self,fromNode=None):
88 """ 89 Override the default, which doesn't account for things on zport 90 """ 91 return ('', 'zport') + super(Portlet, self).getPrimaryPath(fromNode)
92
93 - def get_source(self, debug_mode=False):
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