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

Source Code for Module Products.ZenModel.GraphReport

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  #  
  8  ############################################################################## 
  9   
 10   
 11  from Globals import InitializeClass 
 12  from AccessControl import ClassSecurityInfo 
 13  from Products.ZenMessaging.audit import audit 
 14  from Products.ZenUtils.deprecated import deprecated 
 15  from Products.ZenModel.BaseReport import BaseReport 
 16  from Products.ZenRelations.RelSchema import * 
 17  from GraphReportElement import GraphReportElement 
 18  from Products.ZenUtils.Utils import getObjByPath, getDisplayType 
 19  from Products.ZenUtils.ZenTales import talesCompile, getEngine 
 20  from Products.ZenWidgets import messaging 
 21  from DateTime import DateTime 
22 23 @deprecated 24 -def manage_addGraphReport(context, id, REQUEST = None):
25 """ 26 Create a new GraphReport 27 """ 28 gr = GraphReport(id) 29 context._setObject(gr.id, gr) 30 if REQUEST is not None: 31 audit('UI.Report.Add', gr.id, reportType=getDisplayType(gr), organizer=context) 32 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
33
34 35 -class GraphReport(BaseReport):
36 37 meta_type = "GraphReport" 38 39 numColumns = 1 40 numColumnsOptions = (1, 2, 3) 41 comments = ( 42 '<div style="float: right;"><img src="img/onwhitelogo.png"></div>\n' 43 '<div style="font-size: 16pt;">${report/id}</div>\n' 44 '<div style="font-size:12pt;">${now/aDay} ${now/aMonth} ${now/day},' 45 ' ${now/year}<br />\n' 46 '${now/AMPMMinutes}\n' 47 '</div>\n' 48 '<div style="clear: both" />') 49 50 _properties = BaseReport._properties + ( 51 {'id':'comments', 'type':'text', 'mode':'w'}, 52 {'id':'numColumns', 'type':'int', 53 'select_variable' : 'numColumnOptions', 'mode':'w'}, 54 ) 55 56 _relations = ( 57 ("elements", 58 ToManyCont(ToOne,"Products.ZenModel.GraphReportElement", "report")), 59 ) 60 61 factory_type_information = ( 62 { 63 'immediate_view' : '', 64 'actions' : 65 ( 66 {'name' : 'View Report', 67 'action' : '', 68 'permissions' : ("View",), 69 }, 70 {'name' : 'Edit Report', 71 'action' : 'editGraphReport', 72 'permissions' : ("Manage DMD",), 73 }, 74 ) 75 }, 76 ) 77 78 security = ClassSecurityInfo() 79 80
81 - def getBreadCrumbUrlPath(self):
82 """ 83 Return the url to be used in breadcrumbs for this object. 84 """ 85 return self.getPrimaryUrlPath() + '/editGraphReport'
86
87 - def getThing(self, deviceId, componentPath):
88 """ 89 Return either a device or a component, or None if not found 90 """ 91 thing = self.dmd.Devices.findDevice(deviceId) 92 if thing and componentPath: 93 try: 94 return getObjByPath(thing, componentPath) 95 except KeyError: 96 return None 97 return thing
98 99 100 security.declareProtected('Manage DMD', 'manage_addGraphElement')
101 - def manage_addGraphElement(self, deviceIds='', componentPaths='', 102 graphIds=(), REQUEST=None):
103 """ 104 Add a new graph report element 105 """ 106 def GetId(deviceId, componentPath, graphId): 107 component = componentPath.split('/')[-1] 108 parts = [p for p in (deviceId, component, graphId) if p] 109 root = ' '.join(parts) 110 candidate = self.prepId(root) 111 i = 2 112 while candidate in self.elements.objectIds(): 113 candidate = self.prepId('%s-%s' % (root, i)) 114 i += 1 115 return candidate
116 117 if isinstance(deviceIds, basestring): 118 deviceIds = [deviceIds] 119 if isinstance(componentPaths, basestring): 120 componentPaths = [componentPaths] 121 componentPaths = componentPaths or ('') 122 for devId in deviceIds: 123 dev = self.dmd.Devices.findDevice(devId) 124 for cPath in componentPaths: 125 try: 126 thing = getObjByPath(dev, cPath) 127 except KeyError: 128 continue 129 else: 130 for graphId in graphIds: 131 graph = thing.getGraphDef(graphId) 132 if graph: 133 newId = thing.name 134 if callable(newId): 135 newId = newId() 136 137 newId = GetId(devId, cPath, graphId) 138 ge = GraphReportElement(newId) 139 ge.deviceId = dev.titleOrId() 140 ge.componentPath = cPath 141 ge.graphId = graphId 142 ge.sequence = len(self.elements()) 143 self.elements._setObject(ge.id, ge) 144 if REQUEST: 145 audit('UI.Report.AddGraphElement', self.id, graphelement=ge.id) 146 147 if REQUEST: 148 149 return self.callZenScreen(REQUEST)
150 151 152 security.declareProtected('Manage DMD', 'manage_deleteGraphReportElements')
153 - def manage_deleteGraphReportElements(self, ids=(), REQUEST=None):
154 """ 155 Delete elements from this report 156 """ 157 for id in ids: 158 self.elements._delObject(id) 159 self.manage_resequenceGraphReportElements() 160 if REQUEST: 161 for id in ids: 162 audit('UI.Report.DeleteGraphElement', self.id, graphelement=id) 163 messaging.IMessageSender(self).sendToBrowser( 164 'Graphs Deleted', 165 '%s graph%s were deleted.' % (len(ids), 166 len(ids)>1 and 's' or '') 167 ) 168 return self.callZenScreen(REQUEST)
169 170 171 security.declareProtected('Manage DMD', 172 'manage_resequenceGraphReportElements')
173 - def manage_resequenceGraphReportElements(self, seqmap=(), origseq=(), 174 REQUEST=None):
175 """Reorder the sequecne of the graphs. 176 """ 177 from Products.ZenUtils.Utils import resequence 178 retval = resequence(self, self.elements(), seqmap, origseq, REQUEST) 179 if REQUEST: 180 audit('UI.Report.ResequenceGraphElements', self.id, sequence=seqmap, oldData_={'sequence':origseq}) 181 return retval
182 183 184 security.declareProtected('View', 'getComments')
185 - def getComments(self):
186 """ 187 Returns tales-evaluated comments 188 """ 189 compiled = talesCompile('string:' + self.comments) 190 e = {'rpt': self, 'report': self, 'now':DateTime()} 191 result = compiled(getEngine().getContext(e)) 192 if isinstance(result, Exception): 193 result = 'Error: %s' % str(result) 194 return result
195 196
197 - def getElements(self):
198 """ 199 get the ordered elements 200 """ 201 return sorted(self.elements(), key=lambda a: a.sequence)
202 203 204 InitializeClass(GraphReport) 205