Package Products :: Package ZenModel :: Module ReportClass |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.ReportClass

      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  __doc__="""ReportClass
     15
     16  ReportClass groups different types of reports together
     17
     18  $Id: ReportClass.py,v 1.3 2004/04/22 15:33:44 edahl Exp $"""
     19
     20  __version__ = "$Revision: 1.3 $"[11:-2]
     21
     22  import types
     23
     24  from AccessControl import ClassSecurityInfo
     25  from Globals import InitializeClass
     26  from Globals import DTMLFile
     27
     28  from Organizer import Organizer
     29  from ZenPackable import ZenPackable
     30  from ZenossSecurity import ZEN_COMMON
     31  from Products.ZenRelations.RelSchema import *
     32  from Products.ZenUtils.Utils import unused
     33  from Products.ZenWidgets import messaging
     34
     35 -def manage_addReportClass(context, id, title = None, REQUEST = None):
     36      """make a device class"""
     37      dc = ReportClass(id, title)
     38      context._setObject(id, dc)
     39
     40      if REQUEST is not None:
     41          messaging.IMessageSender(context).sendToBrowser(
     42              'Report Organizer Created',
     43              'Report organizer %s was created.' % id
     44          )
     45          REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
     46
     47  addReportClass = DTMLFile('dtml/addReportClass',globals())
     48
     49 -class ReportClass(Organizer, ZenPackable):
     50      dmdRootName = "Reports"
     51      portal_type = meta_type = "ReportClass"
     52
     53      #sub_meta_types = ("ReportClass", "Report", 'DeviceReport', 'GraphReport',
     54      #                'MultiGraphReportClass')
     55
     56      _relations = Organizer._relations + ZenPackable._relations
     57
     58      # Screen action bindings (and tab definitions)
     59      factory_type_information = (
     60          {
     61              'immediate_view' : 'viewReportClass',
     62              'actions'        :
     63              (
     64                  { 'id'            : 'view'
     65                  , 'name'          : 'Status'
     66                  , 'action'        : 'viewReportClass'
     67                  , 'permissions'   : ( "View",)
     68                  , 'visible'       : 1
     69                  },
     70              )
     71            },
     72          )
     73
     74      security = ClassSecurityInfo()
     75
     76      security.declareProtected(ZEN_COMMON, "children")
     77 -    def children(self, sort=False, checkPerm=True, spec=None):
     78          ''' Return all objects that are instances of ReportClass
     79          '''
     80          unused(spec)
     81          kids = [o for o in self.objectValues() if isinstance(o, ReportClass)]
     82          if checkPerm:
     83              kids = [kid for kid in kids if self.checkRemotePerm("View", kid)]
     84          if sort: kids.sort(lambda x,y: cmp(x.primarySortKey(),
     85                                             y.primarySortKey()))
     86          return kids
     87
     88
     89 -    def childIds(self, spec=None):
     90          """Return Ids of children within our organizer."""
     91          unused(spec)
     92          return [k.id for k in self.children()]
     93
     94
     95      security.declareProtected(ZEN_COMMON, "countChildren")
     96 -    def countChildren(self, spec=None):
     97          """Return a count of all our contained children."""
     98          unused(spec)
     99          count = len(self.childIds())
    100          for child in self.children():
    101              count += child.countChildren()
    102          return count
    103
    104
    105 -    def getReportClass(self):
    106          ''' Return the class to instantiate for new report classes
    107          '''
    108          return ReportClass
    109
    110
    111 -    def manage_addReportClass(self, id, title = None, REQUEST = None):
    112          """make a device class"""
    113          rClass = self.getReportClass()
    114          dc = rClass(id, title)
    115          self._setObject(id, dc)
    116          if REQUEST:
    117              messaging.IMessageSender(self).sendToBrowser(
    118                  'Report Organizer Created',
    119                  'Report organizer %s was created.' % id
    120              )
    121              return self.callZenScreen(REQUEST)
    122
    123
    124 -    def reports(self):
    125          """Return list of report instances.
    126          """
    127          reports = []
    128          for r in self.objectValues(
    129              spec=('Report','DeviceReport','GraphReport','MultiGraphReport')):
    130              if self.checkRemotePerm('View', r):
    131                  reports.append(r)
    132          return reports
    133
    134
    135 -    def countReports(self):
    136          """Return a count of all our contained children."""
    137          count = len(self.reports())
    138          for child in self.children():
    139              count += child.countReports()
    140          return count
    141
    142
    143      security.declareProtected('Manage DMD', 'manage_addGraphReport')
    144 -    def manage_addGraphReport(self, id, REQUEST=None):
    145          """Add an graph report to this object.
    146          """
    147          if id:
    148              from Products.ZenModel.GraphReport import GraphReport
    149              gr = GraphReport(id)
    150              self._setObject(id, gr)
    151          if REQUEST:
    152              messaging.IMessageSender(self).sendToBrowser(
    153                  'Report Created',
    154                  'Graph report %s was created.' % id
    155              )
    156              return self.callZenScreen(REQUEST)
    157
    158
    159 -    def moveReports(self, moveTarget, ids=None, REQUEST=None):
    160          """Move a report from here organizer to moveTarget.
    161          """
    162          if not moveTarget or not ids: return self()
    163          if type(ids) in types.StringTypes: ids = (ids,)
    164          target = self.getOrganizer(moveTarget)
    165          for rptname in ids:
    166              rpt = self._getOb(rptname)
    167              rpt._operation = 1 # moving object state
    168              self._delObject(rptname)
    169              target._setObject(rptname, rpt)
    170          if REQUEST:
    171              messaging.IMessageSender(self).sendToBrowser(
    172                  'Reports Moved',
    173                  'Reports %s were moved to %s.' % (', '.join(ids), moveTarget)
    174              )
    175              REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
    176
    177
    178 -    def exportXmlHook(self, ofile, ignorerels):
    179          """patch to export all device components
    180          """
    181          from Acquisition import aq_base
    182          for o in self.reports():
    183              if hasattr(aq_base(o), 'exportXml'):
    184                  o.exportXml(ofile, ignorerels)
    185
    186
    187
    188  InitializeClass(ReportClass)
    189