1
2
3
4
5
6
7
8
9
10
11
12
13
14 from Globals import InitializeClass
15 from AccessControl import ClassSecurityInfo
16 from ZenModelRM import ZenModelRM
17 from Products.ZenRelations.RelSchema import *
18 from GraphReportElement import GraphReportElement
19 from Products.ZenUtils.Utils import getObjByPath
20 from Products.ZenUtils.ZenTales import talesCompile, getEngine
21 from Products.ZenWidgets import messaging
22 from DateTime import DateTime
23
31
32
34
35 meta_type = "GraphReport"
36
37 numColumns = 1
38 numColumnsOptions = (1, 2, 3)
39 comments = (
40 '<div style="float: right;"><img src="img/onwhitelogo.png"></div>\n'
41 '<div style="font-size: 16pt;">${report/id}</div>\n'
42 '<div style="font-size:12pt;">${now/aDay} ${now/aMonth} ${now/day},'
43 ' ${now/year}<br />\n'
44 '${now/AMPMMinutes}\n'
45 '</div>\n'
46 '<div style="clear: both" />')
47
48 _properties = ZenModelRM._properties + (
49 {'id':'comments', 'type':'text', 'mode':'w'},
50 {'id':'numColumns', 'type':'int',
51 'select_variable' : 'numColumnOptions', 'mode':'w'},
52 )
53
54 _relations = (
55 ("elements",
56 ToManyCont(ToOne,"Products.ZenModel.GraphReportElement", "report")),
57 )
58
59 factory_type_information = (
60 {
61 'immediate_view' : '',
62 'actions' :
63 (
64 {'name' : 'View Report',
65 'action' : '',
66 'permissions' : ("View",),
67 },
68 {'name' : 'Edit Report',
69 'action' : 'editGraphReport',
70 'permissions' : ("Manage DMD",),
71 },
72 )
73 },
74 )
75
76 security = ClassSecurityInfo()
77
78
80 '''
81 Return the url to be used in breadcrumbs for this object.
82 '''
83 return self.getPrimaryUrlPath() + '/editGraphReport'
84
85 - def getThing(self, deviceId, componentPath):
95
96
97 security.declareProtected('Manage DMD', 'manage_addGraphElement')
100 ''' Add a new graph report element
101 '''
102 def GetId(deviceId, componentPath, graphId):
103 component = componentPath.split('/')[-1]
104 parts = [p for p in (deviceId, component, graphId) if p]
105 root = ' '.join(parts)
106 candidate = self.prepId(root)
107 i = 2
108 while candidate in self.elements.objectIds():
109 candidate = self.prepId('%s-%s' % (root, i))
110 i += 1
111 return candidate
112
113 if isinstance(deviceIds, basestring):
114 deviceIds = [deviceIds]
115 if isinstance(componentPaths, basestring):
116 componentPaths = [componentPaths]
117 componentPaths = componentPaths or ('')
118 for devId in deviceIds:
119 dev = self.dmd.Devices.findDevice(devId)
120 for cPath in componentPaths:
121 try:
122 thing = getObjByPath(dev, cPath)
123 except KeyError:
124 continue
125 else:
126 for graphId in graphIds:
127 graph = thing.getGraphDef(graphId)
128 if graph:
129 newId = thing.name
130 if callable(newId):
131 newId = newId()
132
133 newId = GetId(devId, cPath, graphId)
134 ge = GraphReportElement(newId)
135 ge.deviceId = dev.titleOrId()
136 ge.componentPath = cPath
137 ge.graphId = graphId
138 ge.sequence = len(self.elements())
139 self.elements._setObject(ge.id, ge)
140
141 if REQUEST:
142 return self.callZenScreen(REQUEST)
143
144
145 security.declareProtected('Manage DMD', 'manage_deleteGraphReportElements')
159
160
161 security.declareProtected('Manage DMD',
162 'manage_resequenceGraphReportElements')
169
170
171 security.declareProtected('View', 'getComments')
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
199 """get the ordered elements
200 """
201 def cmpElements(a, b):
202 return cmp(a.sequence, b.sequence)
203 elements = [e for e in self.elements()]
204 elements.sort(cmpElements)
205 return elements
206
207
208 InitializeClass(GraphReport)
209