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 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 Products.ZenModel.ZenModelRM import ZenModelRM
    18  from Globals import InitializeClass
    19  from Products.ZenUtils.Utils import zenPath
    20
    21
    22 -def manage_addPortlet(self, context, REQUEST=None):
    23      """
    24      Add a portlet.
    25      """
    26      pass
    27
    28 -class Portlet(ZenModelRM):
    29      """
    30      A wrapper for a portlet javascript source file that can include metadata
    31      such as a name, a title, a description and permissions.
    32
    33      Portlets should not be instantiated directly. They should only be created
    34      by a PortletManager object.
    35      """
    36      source = ''
    37
    38      portal_type = meta_type = 'Portlet'
    39
    40      _relations = (
    41          ("portletManager", ToOne(
    42              ToManyCont, "Products.ZenWidgets.PortletManager", "portlets")),
    43      )
    44
    45      _properties = (
    46          {'id':'title','type':'string','mode':'w'},
    47          {'id':'description', 'type':'string', 'mode':'w'},
    48          {'id':'permission', 'type':'string', 'mode':'w'},
    49          {'id':'sourcepath', 'type':'string', 'mode':'w'},
    50          {'id':'preview', 'type':'string', 'mode':'w'},
    51      )
    52
    53 -    def __init__(self, sourcepath, id='', title='', description='',
    54                   preview='', permission=ZEN_COMMON):
    55          if not id: id = basename(sourcepath).split('.')[0]
    56          self.id = id
    57          ZenModelRM.__init__(self, id)
    58          self.title = title
    59          self.description = description
    60          self.permission = permission
    61          self.sourcepath = sourcepath
    62          self.preview = preview
    63          self._read_source()
    64
    65 -    def _getSourcePath(self):
    66          return zenPath(self.sourcepath)
    67
    68 -    def check(self):
    69          return exists(self._getSourcePath())
    70
    71 -    def _read_source(self):
    72          try:
    73              f = file(self._getSourcePath())
    74          except IOError, e:
    75              return
    76          else:
    77              self.source = f.read()
    78              f.close()
    79
    80 -    def get_source(self, debug_mode=False):
    81          if debug_mode: self._read_source()
    82          src = []
    83          src.append(self.source)
    84          src.append("YAHOO.zenoss.portlet.register_portlet('%s', '%s');" % (
    85              self.id, self.title))
    86          return '\n'.join(src)
    87
    88  InitializeClass(Portlet)
    89