comparison 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
comparison
equal deleted inserted replaced
249:c490de0cf17e 250:141948a400a6
64 64
65 65
66 @route('/graph.png') 66 @route('/graph.png')
67 def graph(): 67 def graph():
68 response.set_header('Content-Type', 'image/png') 68 response.set_header('Content-Type', 'image/png')
69 return make_graph(request.query.length, request.query.end) 69 minutes, endstr = get_request_zoom()
70 return make_graph(minutes, endstr)
70 71
71 @route('/set/update', method='post') 72 @route('/set/update', method='post')
72 def set_update(): 73 def set_update():
73 post_json = json.loads(request.forms.data) 74 post_json = json.loads(request.forms.data)
74 75
92 return bottle.template('set', 93 return bottle.template('set',
93 inline_data = log.get_params(), 94 inline_data = log.get_params(),
94 csrf_blob = secure.get_csrf_blob(), 95 csrf_blob = secure.get_csrf_blob(),
95 allowed = allowed) 96 allowed = allowed)
96 97
97 @route('/') 98 def get_request_zoom():
98 def top(): 99 """ returns (length, end) tuple.
99 100 length is in minutes, end is a DATE_FORMAT string """
100 minutes = int(request.query.get('length', 26*60)) 101 minutes = int(request.query.get('length', 26*60))
101 102
102 if 'end' in request.query: 103 if 'end' in request.query:
103 end = datetime.strptime(request.query.end, DATE_FORMAT) 104 end = datetime.strptime(request.query.end, DATE_FORMAT)
104 else: 105 else:
122 minutes = int(minutes*ZOOM_SCALE) 123 minutes = int(minutes*ZOOM_SCALE)
123 end += timedelta(minutes=minutes/2) 124 end += timedelta(minutes=minutes/2)
124 125
125 if end > datetime.now(): 126 if end > datetime.now():
126 end = datetime.now() 127 end = datetime.now()
127 128
129 endstr = end.strftime(DATE_FORMAT)
130 return (minutes, endstr)
131
132 @route('/')
133 def top():
134 minutes, endstr = get_request_zoom()
135
128 request.query.replace('length', minutes) 136 request.query.replace('length', minutes)
129 request.query.replace('end', end.strftime(DATE_FORMAT)) 137 request.query.replace('end', endstr)
130 138
131 urlparams = urllib.urlencode(request.query) 139 urlparams = urllib.urlencode(request.query)
132 graphdata = encode_data(make_graph(request.query.length, request.query.end), 'image/png') 140 graphdata = encode_data(make_graph(minutes, endstr), 'image/png')
133 return bottle.template('top', urlparams=urlparams, 141 return bottle.template('top', urlparams=urlparams,
134 end = end.strftime(DATE_FORMAT), 142 end = endstr,
135 length = minutes, 143 length = minutes,
136 graphwidth = config.GRAPH_WIDTH, 144 graphwidth = config.GRAPH_WIDTH,
137 graphdata = graphdata) 145 graphdata = graphdata)
138 146
139 @route('/debug') 147 @route('/debug')