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

Source Code for Module ZenModel.DeviceReport

  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  import cgi 
 15  import types 
 16   
 17  from Globals import DTMLFile 
 18  from Globals import InitializeClass 
 19  from AccessControl import ClassSecurityInfo 
 20   
 21  from Products.ZenUtils.ZenTales import talesEval 
 22   
 23  #from Report import Report 
 24  from ZenModelRM import ZenModelRM 
 25   
26 -def manage_addDeviceReport(context, id, title = None, REQUEST = None):
27 """Add a DeviceReport 28 """ 29 dc = DeviceReport(id, title) 30 context._setObject(id, dc) 31 if REQUEST is not None: 32 REQUEST['message'] = "Device report created" 33 return REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
34 35 36
37 -class DeviceReport(ZenModelRM):
38 39 meta_type = "DeviceReport" 40 41 path = "/" 42 deviceQuery = "" 43 sortedHeader = "" 44 sortedSence = "asc" 45 groupby = "" 46 columns = [] 47 colnames = [] 48 49 _properties = ZenModelRM._properties + ( 50 {'id':'path', 'type':'string', 'mode':'w'}, 51 {'id':'deviceQuery', 'type':'string', 'mode':'w'}, 52 {'id':'sortedHeader', 'type':'string', 'mode':'w'}, 53 {'id':'sortedSence', 'type':'string', 'mode':'w'}, 54 {'id':'groupby', 'type':'string', 'mode':'w'}, 55 {'id':'columns', 'type':'lines', 'mode':'w'}, 56 {'id':'colnames', 'type':'lines', 'mode':'w'}, 57 ) 58 59 60 # Screen action bindings (and tab definitions) 61 factory_type_information = ( 62 { 63 'immediate_view' : 'viewDeviceReport', 64 'actions' : 65 ( 66 {'name' : 'Report', 67 'action' : 'viewDeviceReport', 68 'permissions' : ("View",), 69 }, 70 {'name' : 'Edit', 71 'action' : 'editDeviceReport', 72 'permissions' : ("Manage DMD",), 73 }, 74 ) 75 }, 76 ) 77 78 security = ClassSecurityInfo() 79 80
81 - def getDevices(self):
82 """Return the device list for this report. 83 """ 84 devs = self.getDmdRoot("Devices") 85 if self.path != "/": devs = devs.getOrganizer(self.path) 86 devlist = devs.getSubDevices() 87 if self.deviceQuery: 88 return [ dev for dev in devlist \ 89 if talesEval("python:"+self.deviceQuery, dev) ] 90 return devlist
91 92
93 - def testQueryStyle(self):
94 """Return red text style if query is bad. 95 """ 96 try: 97 self.getDevices() 98 except: 99 return "color:#FF0000"
100 101
102 - def testColNamesStyle(self):
103 """Return red text style if columns and colnames not the same length. 104 """ 105 if len(self.columns) != len(self.colnames): return "color:#FF0000"
106 107
108 - def reportHeader(self):
109 h = [] 110 tname = self.getPrimaryId() 111 for i, field in enumerate(self.columns): 112 try:name = self.colnames[i] 113 except IndexError: name = field 114 h.append(self.ZenTableManager.getTableHeader(tname , field, name)) 115 return "\n".join(h)
116 117
118 - def reportHeaders(self):
119 h = [] 120 for i, field in enumerate(self.columns): 121 try:name = self.colnames[i] 122 except IndexError: name = field 123 h.append((field, name)) 124 return h
125 126
127 - def reportBody(self, batch):
128 """body of this report create from a filtered and sorted batch. 129 """ 130 body = [] 131 for dev in batch: 132 body.append("<tr class='tablevalues'>") 133 for field in self.columns: 134 body.append("<td>") 135 if field == "getId": field += "Link" 136 attr = getattr(dev, field) 137 if callable(attr): value = attr() 138 else: value = attr 139 if type(value) in (types.ListType, types.TupleType): 140 value = ", ".join(value) 141 if (not field.endswith("Link") 142 and type(value) in types.StringTypes): 143 value = cgi.escape(value) 144 elif type(value) not in types.StringTypes: 145 value = str(value) 146 body.append(value) 147 body.append("</td>") 148 body.append("</tr>") 149 return "\n".join(body)
150 151 152 InitializeClass(DeviceReport) 153