--- a/pvl/verkko/db.py Wed Oct 10 23:29:38 2012 +0300
+++ b/pvl/verkko/db.py Wed Oct 10 23:36:23 2012 +0300
@@ -6,6 +6,7 @@
# schema
metadata = MetaData()
+# TODO: count, completely separate dhcp_events?
dhcp_hosts = Table('dhcp_hosts', metadata,
Column('rowid', Integer, primary_key=True),
--- a/pvl/verkko/hosts.py Wed Oct 10 23:29:38 2012 +0300
+++ b/pvl/verkko/hosts.py Wed Oct 10 23:36:23 2012 +0300
@@ -108,22 +108,24 @@
html.thead(
html.tr(
html.th(
- html.a(href='?sort={name}'.format(name=sort))(title) if sort else (title)
+ html.a(href=self.url(sort=sort))(title) if sort else (title)
) for title, sort in COLS
)
),
html.tbody(
html.tr(class_=('alternate' if i % 2 else None), id=host.id)(
html.td(class_='id')(
- html.a(href='/hosts/{host.id}'.format(host=host))(
+ html.a(href=self.url(ItemHandler, id=host.id))(
'#' #host['rowid'])
)
),
html.td(class_='ip')(
- html.a(href='/hosts/ip/{host.ip}'.format(host=host))(host.ip)
+ html.a(href=self.url(ListHandler, attr='ip', value=host.ip))(
+ host.ip
+ )
),
html.td(class_='mac')(
- html.a(href='/hosts/mac/{host.mac}'.format(host=host))(
+ html.a(href=self.url(ListHandler, attr='mac', value=host.mac))(
host.render_mac()
)
),
@@ -150,7 +152,7 @@
html.h2('Related'),
self.render_hosts(hosts),
- html.a(href='/hosts')(html('«'), 'Back'),
+ html.a(href=self.url(IndexHandler))(html('«'), 'Back'),
)
class IndexHandler (BaseHandler) :
--- a/pvl/verkko/web.py Wed Oct 10 23:29:38 2012 +0300
+++ b/pvl/verkko/web.py Wed Oct 10 23:36:23 2012 +0300
@@ -34,6 +34,16 @@
self.db = app.db
self.request = request
self.urlmap = urls
+
+ def url (self, handler=None, **params) :
+ """
+ Return an URL for given endpoint, with parameters,
+ """
+
+ if not handler :
+ handler = self.__class__
+
+ return self.urlmap.build(handler, params)
def title (self) :
"""
@@ -100,6 +110,7 @@
def render (self) :
return (
html.ul(
+ # TODO: self.url
html.a(href='/hosts')("DHCP Hosts"),
)
)