diff web/templog.py @ 250:141948a400a6

working zoom
author Matt Johnston <matt@ucc.asn.au>
date Wed, 27 May 2015 23:45:03 +0800
parents c490de0cf17e
children 3e6f82347eab 0a1b642e3086
line wrap: on
line diff
--- a/web/templog.py	Wed May 27 22:37:43 2015 +0800
+++ b/web/templog.py	Wed May 27 23:45:03 2015 +0800
@@ -66,7 +66,8 @@
 @route('/graph.png')
 def graph():
     response.set_header('Content-Type', 'image/png')
-    return make_graph(request.query.length, request.query.end)
+    minutes, endstr = get_request_zoom()
+    return make_graph(minutes, endstr)
 
 @route('/set/update', method='post')
 def set_update():
@@ -94,9 +95,9 @@
         csrf_blob = secure.get_csrf_blob(),
         allowed = allowed)
 
-@route('/')
-def top():
-
+def get_request_zoom():
+    """ returns (length, end) tuple.
+    length is in minutes, end is a DATE_FORMAT string """
     minutes = int(request.query.get('length', 26*60))
 
     if 'end' in request.query:
@@ -124,14 +125,21 @@
 
     if end > datetime.now():
         end = datetime.now()
-        
+
+    endstr = end.strftime(DATE_FORMAT)
+    return (minutes, endstr)
+
+@route('/')
+def top():
+    minutes, endstr = get_request_zoom()
+
     request.query.replace('length', minutes)
-    request.query.replace('end', end.strftime(DATE_FORMAT))
+    request.query.replace('end', endstr)
 
     urlparams = urllib.urlencode(request.query)
-    graphdata = encode_data(make_graph(request.query.length, request.query.end), 'image/png')
+    graphdata = encode_data(make_graph(minutes, endstr), 'image/png')
     return bottle.template('top', urlparams=urlparams,
-                    end = end.strftime(DATE_FORMAT),
+                    end = endstr,
                     length = minutes,
                     graphwidth = config.GRAPH_WIDTH,
                     graphdata = graphdata)