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

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