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