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.ZenTales import talesCompile, getEngine
20 from Products.ZenWidgets import messaging
21 from DateTime import DateTime
22
30
31
33
34 meta_type = "GraphReport"
35
36 numColumns = 1
37 numColumnsOptions = (1, 2, 3)
38 comments = (
39 '<div style="float: right;"><img src="img/onwhitelogo.png"></div>\n'
40 '<div style="font-size: 16pt;">${report/id}</div>\n'
41 '<div style="font-size:12pt;">${now/aDay} ${now/aMonth} ${now/day},'
42 ' ${now/year}<br />\n'
43 '${now/AMPMMinutes}\n'
44 '</div>\n'
45 '<div style="clear: both" />')
46
47 _properties = ZenModelRM._properties + (
48 {'id':'comments', 'type':'text', 'mode':'w'},
49 {'id':'numColumns', 'type':'int',
50 'select_variable' : 'numColumnOptions', 'mode':'w'},
51 )
52
53 _relations = (
54 ("elements",
55 ToManyCont(ToOne,"Products.ZenModel.GraphReportElement", "report")),
56 )
57
58 factory_type_information = (
59 {
60 'immediate_view' : 'viewGraphReport',
61 'actions' :
62 (
63 {'name' : 'Report',
64 'action' : 'viewGraphReport',
65 'permissions' : ("View",),
66 },
67 {'name' : 'Edit',
68 'action' : 'editGraphReport',
69 'permissions' : ("Manage DMD",),
70 },
71 )
72 },
73 )
74
75 security = ClassSecurityInfo()
76
77
79 '''
80 Return the url to be used in breadcrumbs for this object.
81 '''
82 return self.getPrimaryUrlPath() + '/editGraphReport'
83
84 - def getThing(self, deviceId, componentPath):
85 ''' Return either a device or a component, or None if not found
86 '''
87 thing = self.dmd.Devices.findDevice(deviceId)
88 if thing and componentPath:
89 parts = componentPath.split('/')
90 for part in parts:
91 if hasattr(thing, part):
92 thing = getattr(thing, part)
93 else:
94 thing = None
95 break
96 return thing
97
98
99 security.declareProtected('Manage DMD', 'manage_addGraphElement')
102 ''' Add a new graph report element
103 '''
104 def GetId(deviceId, componentPath, graphId):
105 component = componentPath.split('/')[-1]
106 parts = [p for p in (deviceId, component, graphId) if p]
107 root = ' '.join(parts)
108 candidate = self.prepId(root)
109 i = 2
110 while candidate in self.elements.objectIds():
111 candidate = self.prepId('%s-%s' % (root, i))
112 i += 1
113 return candidate
114
115 if isinstance(deviceIds, basestring):
116 deviceIds = [deviceIds]
117 if isinstance(componentPaths, basestring):
118 componentPaths = [componentPaths]
119 componentPaths = componentPaths or ('')
120 for devId in deviceIds:
121 for cPath in componentPaths:
122 thing = self.getThing(devId, cPath)
123 if thing:
124 for graphId in graphIds:
125 graph = thing.getGraphDef(graphId)
126 if graph:
127 newId = GetId(devId, cPath, graphId)
128 ge = GraphReportElement(newId)
129 ge.deviceId = devId
130 ge.componentPath = cPath
131 ge.graphId = graphId
132 ge.sequence = len(self.elements())
133 self.elements._setObject(ge.id, ge)
134
135 if REQUEST:
136 return self.callZenScreen(REQUEST)
137
138
139 security.declareProtected('Manage DMD', 'manage_deleteGraphReportElements')
153
154
155 security.declareProtected('Manage DMD',
156 'manage_resequenceGraphReportElements')
163
164
165 security.declareProtected('View', 'getComments')
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
193 """get the ordered elements
194 """
195 def cmpElements(a, b):
196 return cmp(a.sequence, b.sequence)
197 elements = [e for e in self.elements()]
198 elements.sort(cmpElements)
199 return elements
200
201
202 InitializeClass(GraphReport)
203