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 -def manage_addPortlet(self, context, REQUEST=None):
    22      """
    23      Add a portlet.
    24      """
    25      pass
    26
    27 -class Portlet(ZenModelRM):
    28      """
    29      A wrapper for a portlet javascript source file that can include metadata
    30      such as a name, a title, a description and permissions.
    31
    32      Portlets should not be instantiated directly. They should only be created
    33      by a PortletManager object.
    34      """
    35      source = ''
    36
    37      portal_type = meta_type = 'Portlet'
    38
    39      _relations = (
    40          ("portletManager", ToOne(
    41              ToManyCont, "Products.ZenWidgets.PortletManager", "portlets")),
    42      )
    43
    44      _properties = (
    45          {'id':'title','type':'string','mode':'w'},
    46          {'id':'description', 'type':'string', 'mode':'w'},
    47          {'id':'permission', 'type':'string', 'mode':'w'},
    48          {'id':'sourcepath', 'type':'string', 'mode':'w'},
    49          {'id':'preview', 'type':'string', 'mode':'w'},
    50      )
    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 getPrimaryPath(self,fromNode=None):
    81          """
    82          Override the default, which doesn't account for things on zport
    83          """
    84          return ('', 'zport') + super(Portlet, self).getPrimaryPath(fromNode)
    85
    86 -    def get_source(self, debug_mode=False):
    87          if debug_mode: self._read_source()
    88          src = []
    89          src.append(self.source)
    90          src.append("YAHOO.zenoss.portlet.register_portlet('%s', '%s');" % (
    91              self.id, self.title))
    92          return '\n'.join(src)
    93
    94  InitializeClass(Portlet)
    95