1
2
3
4
5
6
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
33
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
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):
98
99
100 security.declareProtected('Manage DMD', 'manage_addGraphElement')
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')
169
170
171 security.declareProtected('Manage DMD',
172 'manage_resequenceGraphReportElements')
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')
195
196
198 """
199 get the ordered elements
200 """
201 return sorted(self.elements(), key=lambda a: a.sequence)
202
203
204 InitializeClass(GraphReport)
205