equal
deleted
inserted
replaced
150 hosts = hosts.order_by(sort) |
150 hosts = hosts.order_by(sort) |
151 |
151 |
152 # k |
152 # k |
153 return hosts |
153 return hosts |
154 |
154 |
155 def render_hosts (self, hosts, title=None, filters=False, page=None) : |
155 def render_hosts (self, hosts, title=None, filters=False, page=None, hilight=None) : |
156 COLS = ( |
156 COLS = ( |
157 #title sort filter class |
157 #title sort filter class |
158 ('IP', 'ip', 'ip', 'ip' ), |
158 ('IP', 'ip', 'ip', 'ip' ), |
159 ('MAC', 'mac', 'mac', 'mac' ), |
159 ('MAC', 'mac', 'mac', 'mac' ), |
160 ('Hostname', 'name', False, False ), |
160 ('Hostname', 'name', False, False ), |
199 value = value[0] |
199 value = value[0] |
200 else : |
200 else : |
201 value = None |
201 value = None |
202 |
202 |
203 return html.input(type='text', name=filter, value=value) |
203 return html.input(type='text', name=filter, value=value) |
|
204 |
|
205 def render_cell (attr, value, cssclass=True, filter=None, htmlvalue=None) : |
|
206 |
|
207 if htmlvalue : |
|
208 cell = htmlvalue |
|
209 else : |
|
210 cell = value |
|
211 |
|
212 if filter : |
|
213 cell = html.a(href=url(**{attr: value}))(value) |
|
214 |
|
215 if cssclass is True : |
|
216 cssclass = attr |
|
217 |
|
218 css = (cssclass, 'hilight' if (hilight and attr in hilight and value in hilight[attr]) else None) |
|
219 css = ' '.join(cls for cls in css if cls) |
|
220 |
|
221 return html.td(class_=css)(cell) |
204 |
222 |
205 table = html.table( |
223 table = html.table( |
206 html.caption(title) if title else None, |
224 html.caption(title) if title else None, |
207 html.thead( |
225 html.thead( |
208 html.tr( |
226 html.tr( |
229 html.th( |
247 html.th( |
230 html.a(href=self.url(ItemHandler, id=host.id))( |
248 html.a(href=self.url(ItemHandler, id=host.id))( |
231 '#' #host.id |
249 '#' #host.id |
232 ) |
250 ) |
233 ), |
251 ), |
234 html.td(class_='ip')( |
252 |
235 html.a(href=url(ip=host.ip))( |
253 render_cell('ip', host.ip, filter=True), |
236 host.ip |
254 render_cell('mac', host.mac, filter=True, htmlvalue=host.render_mac()), |
237 ) |
255 render_cell('name', host.name, htmlvalue=host.render_name()), |
238 ), |
256 render_cell('gw', host.gw), |
239 html.td(class_='mac')( |
257 |
240 html.a(href=url(mac=host.mac))( |
|
241 host.render_mac() |
|
242 ) |
|
243 ), |
|
244 html.td(host.render_name()), |
|
245 html.td( |
|
246 host.gw |
|
247 ), |
|
248 html.td(host.when()), |
258 html.td(host.when()), |
249 html.td(class_=host.state_class(), title=host.state_title())(host.state), |
259 html.td(class_=host.state_class(), title=host.state_title())(host.state), |
250 ) for i, host in enumerate(hosts) |
260 ) for i, host in enumerate(hosts) |
251 ), |
261 ), |
252 html.tfoot( |
262 html.tfoot( |
309 return ( |
319 return ( |
310 html.h2('Host'), |
320 html.h2('Host'), |
311 self.render_host(self.host), |
321 self.render_host(self.host), |
312 |
322 |
313 html.h2('Related'), |
323 html.h2('Related'), |
314 self.render_hosts(self.hosts), |
324 self.render_hosts(self.hosts, hilight=dict(ip=self.host.ip, mac=self.host.mac)), |
315 |
325 |
316 html.a(href=self.url(ListHandler))(html('«'), 'Back'), |
326 html.a(href=self.url(ListHandler))(html('«'), 'Back'), |
317 ) |
327 ) |
318 |
328 |
319 |
329 |