1
2
3
4
5
6
7
8
9
10
11
12
13
14 import cgi
15 import types
16
17 from Globals import DTMLFile
18 from Globals import InitializeClass
19 from AccessControl import ClassSecurityInfo
20
21 from Products.ZenUtils.ZenTales import talesEval
22
23
24 from ZenModelRM import ZenModelRM
25
34
35
36
38
39 meta_type = "DeviceReport"
40
41 path = "/"
42 deviceQuery = ""
43 sortedHeader = ""
44 sortedSence = "asc"
45 groupby = ""
46 columns = []
47 colnames = []
48
49 _properties = ZenModelRM._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' : 'viewDeviceReport',
64 'actions' :
65 (
66 {'name' : 'Report',
67 'action' : 'viewDeviceReport',
68 'permissions' : ("View",),
69 },
70 {'name' : 'Edit',
71 'action' : 'editDeviceReport',
72 'permissions' : ("Manage DMD",),
73 },
74 )
75 },
76 )
77
78 security = ClassSecurityInfo()
79
80
91
92
94 """Return red text style if query is bad.
95 """
96 try:
97 self.getDevices()
98 except:
99 return "color:#FF0000"
100
101
103 """Return red text style if columns and colnames not the same length.
104 """
105 if len(self.columns) != len(self.colnames): return "color:#FF0000"
106
107
116
117
125
126
127 - def reportBody(self, batch):
128 """body of this report create from a filtered and sorted batch.
129 """
130 body = []
131 for dev in batch:
132 body.append("<tr class='tablevalues'>")
133 for field in self.columns:
134 body.append("<td>")
135 if field == "getId": field += "Link"
136 attr = getattr(dev, field)
137 if callable(attr): value = attr()
138 else: value = attr
139 if type(value) in (types.ListType, types.TupleType):
140 value = ", ".join(value)
141 if (not field.endswith("Link")
142 and type(value) in types.StringTypes):
143 value = cgi.escape(value)
144 elif type(value) not in types.StringTypes:
145 value = str(value)
146 body.append(value)
147 body.append("</td>")
148 body.append("</tr>")
149 return "\n".join(body)
150
151
152 InitializeClass(DeviceReport)
153