pvl/verkko/hosts.py
changeset 178 f9f5e669bace
parent 158 3ff66d4f401c
child 179 706972d09f05
--- a/pvl/verkko/hosts.py	Sat Jan 26 14:40:05 2013 +0200
+++ b/pvl/verkko/hosts.py	Sat Jan 26 17:52:40 2013 +0200
@@ -1,4 +1,4 @@
-from pvl.verkko import db, web
+from pvl.verkko import web, db
 from pvl.verkko.utils import parse_timedelta, IPv4Network
 
 from pvl.web import html
@@ -10,7 +10,17 @@
 
 import logging; log = logging.getLogger('pvl.verkko.hosts')
 
-# XXX: this should actually be DHCPHost
+## Model
+import json
+import time
+
+def dt2ts (dt) :
+    return int(time.mktime(dt.timetuple()))
+
+def ts2dt (ts) :
+    return datetime.datetime.fromtimestamp(ts)
+
+# TODO: this should be DHCPHost
 class Host (object) :
     DATE_FMT = '%Y%m%d'
     TIME_FMT = '%H:%M:%S'
@@ -129,10 +139,19 @@
     #state   = db.dhcp_hosts.c.,
 ))
 
+## Controller 
+class BaseHandler (web.DatabaseHandler) :
+    """
+        Common controller stuff for DHCP hosts
+    """
 
-   
- 
-class BaseHandler (web.Handler) :
+    CSS = (
+        "/static/dhcp/hosts.css", 
+    )
+    JS = (
+        #"/static/jquery/jquery.js"
+    )
+
     HOST_ATTRS = {
         'id':       Host.id,
         'net':      Host.gw,
@@ -408,6 +427,10 @@
             )
 
 class ItemHandler (BaseHandler) :
+    """
+        A specific DHCP host, along with a list of related hosts.
+    """
+
     def process (self, id) :
         self.hosts = self.query()
         self.host = self.hosts.get(id)
@@ -456,29 +479,13 @@
 
 
 class ListHandler (BaseHandler) :
+    """
+        List of DHCP hosts for given filter.
+    """
+
     # pagination
     PAGE = 10
 
-    # views
-    VIEWS = (
-        ("Last hour",   dict(seen='1h')),
-        ("Last day",    dict(seen='24h')),
-        ("All",         dict()),
-    ) + tuple(
-        ("Network " + network,          dict(ip=network)) for network in (
-            '194.197.235.0/24',
-            '10.1.0.0/16',
-            '10.4.0.0/16',
-            '10.5.0.0/16',
-            '10.6.0.0/16',
-            '10.10.0.0/16',
-        )
-    ) + (
-        ("Valid",       dict(state=('DHCPACK', 'DHCPRELEASE'))),
-        ("Incomplete",  dict(state=('DHCPDISCOVER', 'DHCPOFFER', 'DHCPREQUEST'))),
-        ("Invalid",     dict(state=('DHCPNAK', ))),
-    )
-
     def process (self) :
         hosts = self.query()
 
@@ -511,18 +518,9 @@
             html.a(href=self.url())(html('«'), 'Back') if self.filters else None,
         )
 
-import json
-import time
-
-def dt2ts (dt) :
-    return int(time.mktime(dt.timetuple()))
-
-def ts2dt (ts) :
-    return datetime.datetime.fromtimestamp(ts)
-
 class RealtimeHandler (BaseHandler) :
-    TITLE = "Pseudo-Realtime hosts.."
-    CSS = web.Handler.CSS + (
+    TITLE = "DHCP Pseudo-Realtime hosts.."
+    CSS = BaseHandler.CSS + (
         'http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css',
     )
     JS = (