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