# HG changeset patch # User Tero Marttila # Date 1349901383 -10800 # Node ID 0f243c59d5d143637ac287bc5610d99ab2914c7d # Parent 91970ce3fc6b2d6566c52683d283abf2dd0f604a build urls diff -r 91970ce3fc6b -r 0f243c59d5d1 pvl/verkko/db.py --- 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), diff -r 91970ce3fc6b -r 0f243c59d5d1 pvl/verkko/hosts.py --- 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) : diff -r 91970ce3fc6b -r 0f243c59d5d1 pvl/verkko/web.py --- 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"), ) )