--- a/pvl/verkko/hosts.py Wed Oct 24 16:14:48 2012 +0300
+++ b/pvl/verkko/hosts.py Wed Oct 24 16:25:50 2012 +0300
@@ -152,7 +152,7 @@
# k
return hosts
- def render_hosts (self, hosts, title=None, filters=False, page=None) :
+ def render_hosts (self, hosts, title=None, filters=False, page=None, hilight=None) :
COLS = (
#title sort filter class
('IP', 'ip', 'ip', 'ip' ),
@@ -202,6 +202,24 @@
return html.input(type='text', name=filter, value=value)
+ def render_cell (attr, value, cssclass=True, filter=None, htmlvalue=None) :
+
+ if htmlvalue :
+ cell = htmlvalue
+ else :
+ cell = value
+
+ if filter :
+ cell = html.a(href=url(**{attr: value}))(value)
+
+ if cssclass is True :
+ cssclass = attr
+
+ css = (cssclass, 'hilight' if (hilight and attr in hilight and value in hilight[attr]) else None)
+ css = ' '.join(cls for cls in css if cls)
+
+ return html.td(class_=css)(cell)
+
table = html.table(
html.caption(title) if title else None,
html.thead(
@@ -231,20 +249,12 @@
'#' #host.id
)
),
- html.td(class_='ip')(
- html.a(href=url(ip=host.ip))(
- host.ip
- )
- ),
- html.td(class_='mac')(
- html.a(href=url(mac=host.mac))(
- host.render_mac()
- )
- ),
- html.td(host.render_name()),
- html.td(
- host.gw
- ),
+
+ render_cell('ip', host.ip, filter=True),
+ render_cell('mac', host.mac, filter=True, htmlvalue=host.render_mac()),
+ render_cell('name', host.name, htmlvalue=host.render_name()),
+ render_cell('gw', host.gw),
+
html.td(host.when()),
html.td(class_=host.state_class(), title=host.state_title())(host.state),
) for i, host in enumerate(hosts)
@@ -311,7 +321,7 @@
self.render_host(self.host),
html.h2('Related'),
- self.render_hosts(self.hosts),
+ self.render_hosts(self.hosts, hilight=dict(ip=self.host.ip, mac=self.host.mac)),
html.a(href=self.url(ListHandler))(html('«'), 'Back'),
)