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, ZEN_MANAGE_DMD 
 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 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addReportClass')
112 - def manage_addReportClass(self, id, title = None, REQUEST = None):
113 """make a device class""" 114 rClass = self.getReportClass() 115 dc = rClass(id, title) 116 self._setObject(id, dc) 117 if REQUEST: 118 messaging.IMessageSender(self).sendToBrowser( 119 'Report Organizer Created', 120 'Report organizer %s was created.' % id 121 ) 122 return self.callZenScreen(REQUEST)
123 124
125 - def reports(self):
126 """Return list of report instances. 127 """ 128 reports = [] 129 for r in self.objectValues( 130 spec=('Report','DeviceReport','GraphReport','MultiGraphReport')): 131 if self.checkRemotePerm('View', r): 132 reports.append(r) 133 return reports
134 135
136 - def countReports(self):
137 """Return a count of all our contained children.""" 138 count = len(self.reports()) 139 for child in self.children(): 140 count += child.countReports() 141 return count
142 143 144 security.declareProtected('Manage DMD', 'manage_addGraphReport')
145 - def manage_addGraphReport(self, id, REQUEST=None):
146 """Add an graph report to this object. 147 """ 148 if id: 149 from Products.ZenModel.GraphReport import GraphReport 150 gr = GraphReport(id) 151 self._setObject(id, gr) 152 if REQUEST: 153 messaging.IMessageSender(self).sendToBrowser( 154 'Report Created', 155 'Graph report %s was created.' % id 156 ) 157 return self.callZenScreen(REQUEST)
158 159
160 - def moveReports(self, moveTarget, ids=None, REQUEST=None):
161 """Move a report from here organizer to moveTarget. 162 """ 163 if not moveTarget or not ids: return self() 164 if type(ids) in types.StringTypes: ids = (ids,) 165 target = self.getOrganizer(moveTarget) 166 for rptname in ids: 167 rpt = self._getOb(rptname) 168 rpt._operation = 1 # moving object state 169 self._delObject(rptname) 170 target._setObject(rptname, rpt) 171 if REQUEST: 172 messaging.IMessageSender(self).sendToBrowser( 173 'Reports Moved', 174 'Reports %s were moved to %s.' % (', '.join(ids), moveTarget) 175 ) 176 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
177 178
179 - def exportXmlHook(self, ofile, ignorerels):
180 """patch to export all device components 181 """ 182 from Acquisition import aq_base 183 for o in self.reports(): 184 if hasattr(aq_base(o), 'exportXml'): 185 o.exportXml(ofile, ignorerels)
186 187 188 189 InitializeClass(ReportClass) 190