fixup index + non-chunked response (?) + hosts + evil hardcoded db url
authorTero Marttila <terom@paivola.fi>
Wed, 10 Oct 2012 21:59:34 +0300
changeset 1 731d2df704f0
parent 0 91c739202f06
child 2 b0659c867226
fixup index + non-chunked response (?) + hosts + evil hardcoded db url
pvl/verkko/db.py
pvl/verkko/hosts.py
pvl/verkko/web.py
pvl/verkko/wsgi.py
--- a/pvl/verkko/db.py	Wed Oct 10 21:39:54 2012 +0300
+++ b/pvl/verkko/db.py	Wed Oct 10 21:59:34 2012 +0300
@@ -3,7 +3,7 @@
 
 import logging; log = logging.getLogger('pvl.verkko.db')
 
-DATABASE = 'sqlite:///var/verkko.db'
+DATABASE = 'sqlite:////home/terom/pvl/web/verkko/var/verkko.db'
 
 # schema
 metadata = MetaData()
--- a/pvl/verkko/hosts.py	Wed Oct 10 21:39:54 2012 +0300
+++ b/pvl/verkko/hosts.py	Wed Oct 10 21:59:34 2012 +0300
@@ -6,6 +6,7 @@
 
 import logging; log = logging.getLogger('pvl.verkko.hosts')
 
+# XXX: this should actually be DHCPHost
 class Host (object) :
     DATE_FMT = '%Y%m%d'
 
@@ -131,11 +132,9 @@
         html.h2('Related'),
         render_hosts(hosts),
 
-        html.a(href='/')(html('&laquo;'), 'Back'),
+        html.a(href='/hosts')(html('&laquo;'), 'Back'),
     )
 
-from werkzeug.wrappers import Response
-
 def respond (request, db, path) :
     """
         Handle request
@@ -193,5 +192,5 @@
     # render
     html = web.render_layout(title, html)
 
-    return Response(html, content_type='text/html; charset=UTF-8')
+    return web.Response(html, content_type='text/html; charset=UTF-8')
 
--- a/pvl/verkko/web.py	Wed Oct 10 21:39:54 2012 +0300
+++ b/pvl/verkko/web.py	Wed Oct 10 21:59:34 2012 +0300
@@ -1,3 +1,5 @@
+from werkzeug.wrappers import Response
+
 # view
 from pvl.html import tags as html
 
@@ -7,7 +9,7 @@
         "/static/style.css", 
     ]
 
-    return html.document(html.html(
+    return unicode(html.document(html.html(
         html.head(
             html.title(title),
             (
@@ -18,6 +20,12 @@
             html.h1(title),
             content 
         )
-    ))
+    )))
 
+def render_index () :
+    return Response(render_layout("Verkko", (
+        html.ul(
+            html.a(href='/hosts')("DHCP Hosts"),
+        )
+    )), content_type='text/html')
 
--- a/pvl/verkko/wsgi.py	Wed Oct 10 21:39:54 2012 +0300
+++ b/pvl/verkko/wsgi.py	Wed Oct 10 21:59:34 2012 +0300
@@ -4,7 +4,7 @@
 
 import logging; log = logging.getLogger('pvl.verkko.wsgi')
 
-from pvl.verkko import db as database, hosts
+from pvl.verkko import db as database, web, hosts
 
 @Request.application
 def application (request) :
@@ -22,7 +22,7 @@
     
     # respond
     if not path :
-        return redirect('/hosts')
+        return web.render_index()
 
     elif path[0] == 'hosts' :
         return hosts.respond(request, db, path[1:])