1
2
3
4
5
6
7
8
9
10
11 import cgi
12 from Globals import InitializeClass
13 from AccessControl import ClassSecurityInfo
14 from Products.ZenMessaging.audit import audit
15 from Products.ZenUtils.ZenTales import talesEval
16 from Products.ZenUtils.Utils import convToUnits, zdecode, getDisplayType
17 from Products.ZenWidgets import messaging
18 from Products.ZenUtils.deprecated import deprecated
19 from Products.ZenModel.BaseReport import BaseReport
34
38
39 meta_type = "DeviceReport"
40
41 path = "/"
42 deviceQuery = ""
43 sortedHeader = ""
44 sortedSence = "asc"
45 groupby = ""
46 columns = []
47 colnames = []
48
49 _properties = BaseReport._properties + (
50 {'id':'path', 'type':'string', 'mode':'w'},
51 {'id':'deviceQuery', 'type':'string', 'mode':'w'},
52 {'id':'sortedHeader', 'type':'string', 'mode':'w'},
53 {'id':'sortedSence', 'type':'string', 'mode':'w'},
54 {'id':'groupby', 'type':'string', 'mode':'w'},
55 {'id':'columns', 'type':'lines', 'mode':'w'},
56 {'id':'colnames', 'type':'lines', 'mode':'w'},
57 )
58
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' : 'editDeviceReport',
72 'permissions' : ("Manage DMD",),
73 },
74 )
75 },
76 )
77
78 security = ClassSecurityInfo()
79
81 '''
82 Return the url to be used in breadcrumbs for this object.
83 '''
84 return self.getPrimaryUrlPath() + '/editDeviceReport'
85
86
100
101
103 """Return red text style if query is bad.
104 """
105 try:
106 self.getDevices()
107 except:
108 return "color:#FF0000"
109
110
112 """Return red text style if columns and colnames not the same length.
113 """
114 if len(self.columns) != len(self.colnames): return "color:#FF0000"
115
116
125
126
134
135
136 - def reportBody(self, batch):
137 """body of this report create from a filtered and sorted batch.
138 """
139 body = []
140 for dev in batch:
141
142 if isinstance(dev, basestring):
143 body.extend([
144 '<tr class="tablevalues">',
145 ' <td colspan="%d" align="center">' % len(self.columns),
146 ' Query error: %s' % dev,
147 ' </td>',
148 '</tr>',
149 ])
150 else:
151 body.append("<tr class='tablevalues'>")
152 for field in self.columns:
153 body.append("<td>")
154 if field == "getId": field += "Link"
155
156
157 if dev.zenPropIsPassword(field):
158 attr = '*****'
159 else:
160 attr = getattr(dev, field, 'Unknown column')
161 variables_and_funcs = {
162 'device':dev, 'dev':dev, 'attr':attr,
163 'convToUnits':convToUnits, 'zdecode':zdecode,
164 }
165 if field.startswith('python:'):
166 expression = field.replace('python:', 'attr=')
167 try:
168 exec(expression, variables_and_funcs)
169 attr = variables_and_funcs['attr']
170 except Exception, ex:
171 attr = str(ex)
172
173 if callable(attr):
174 try: value = attr()
175 except Exception, ex:
176 value = str(ex)
177 else: value = attr
178
179 if isinstance(value, (list, tuple, set)):
180
181 try: value = ", ".join(value)
182 except Exception, ex:
183 value = str(ex)
184 if (not field.endswith("Link")
185 and isinstance(value, basestring)):
186 value = cgi.escape(value)
187 elif isinstance(value, basestring):
188 value = str(value)
189 body.append(value)
190 body.append("</td>")
191 body.append("</tr>")
192
193 return "\n".join(body)
194
195
196 InitializeClass(DeviceReport)
197