1
2
3
4
5
6
7
8
9
10
11
12
13
14 import cgi
15 import types
16
17 from Globals import InitializeClass
18 from AccessControl import ClassSecurityInfo
19
20 from Products.ZenUtils.ZenTales import talesEval
21 from Products.ZenWidgets import messaging
22
23
24 from ZenModelRM import ZenModelRM
25
37
38
39
41
42 meta_type = "DeviceReport"
43
44 path = "/"
45 deviceQuery = ""
46 sortedHeader = ""
47 sortedSence = "asc"
48 groupby = ""
49 columns = []
50 colnames = []
51
52 _properties = ZenModelRM._properties + (
53 {'id':'path', 'type':'string', 'mode':'w'},
54 {'id':'deviceQuery', 'type':'string', 'mode':'w'},
55 {'id':'sortedHeader', 'type':'string', 'mode':'w'},
56 {'id':'sortedSence', 'type':'string', 'mode':'w'},
57 {'id':'groupby', 'type':'string', 'mode':'w'},
58 {'id':'columns', 'type':'lines', 'mode':'w'},
59 {'id':'colnames', 'type':'lines', 'mode':'w'},
60 )
61
62
63
64 factory_type_information = (
65 {
66 'immediate_view' : 'viewDeviceReport',
67 'actions' :
68 (
69 {'name' : 'Report',
70 'action' : 'viewDeviceReport',
71 'permissions' : ("View",),
72 },
73 {'name' : 'Edit',
74 'action' : 'editDeviceReport',
75 'permissions' : ("Manage DMD",),
76 },
77 )
78 },
79 )
80
81 security = ClassSecurityInfo()
82
83
97
98
100 """Return red text style if query is bad.
101 """
102 try:
103 self.getDevices()
104 except:
105 return "color:#FF0000"
106
107
109 """Return red text style if columns and colnames not the same length.
110 """
111 if len(self.columns) != len(self.colnames): return "color:#FF0000"
112
113
122
123
125 h = []
126 for i, field in enumerate(self.columns):
127 try:name = self.colnames[i]
128 except IndexError: name = field
129 h.append((field, name))
130 return h
131
132
133 - def reportBody(self, batch):
134 """body of this report create from a filtered and sorted batch.
135 """
136 body = []
137 for dev in batch:
138
139 if type(dev) in types.StringTypes:
140 body.extend([
141 '<tr class="tablevalues">',
142 ' <td colspan="%d" align="center">' % len(self.columns),
143 ' Query error: %s' % dev,
144 ' </td>',
145 '</tr>',
146 ])
147 else:
148 body.append("<tr class='tablevalues'>")
149 for field in self.columns:
150 body.append("<td>")
151 if field == "getId": field += "Link"
152 attr = getattr(dev, field, 'Unknown column')
153 if callable(attr): value = attr()
154 else: value = attr
155 if type(value) in (types.ListType, types.TupleType):
156 value = ", ".join(value)
157 if (not field.endswith("Link")
158 and type(value) in types.StringTypes):
159 value = cgi.escape(value)
160 elif type(value) not in types.StringTypes:
161 value = str(value)
162 body.append(value)
163 body.append("</td>")
164 body.append("</tr>")
165
166 return "\n".join(body)
167
168
169 InitializeClass(DeviceReport)
170