Download:
child 29:58bcac03bba9
parent 27:e5098c3301fb
28:f834362f7f83
Anton Shestakov <engored@ya.ru>, Thu, 28 May 2015 15:11:01 +0800
viewer: set rev and local query string parameters independently

2 файлов изменено, 44 вставок(+), 9 удалений(-) [+]
templates/results.html file | annotate | diff | comparison | revisions
viewer.py file | annotate | diff | comparison | revisions
--- a/templates/results.html Wed May 27 18:57:30 2015 +0800
+++ b/templates/results.html Thu May 28 15:11:01 2015 +0800
@@ -34,14 +34,18 @@
<header>
<a href="/results.html">back to tip</a>
{% set prevrev = changesets[0]['rev'] + 120 if changesets else None %}
- {% if prevrev %}<a href="?rev=rev({{ prevrev }})">prev page</a>{% end %}
+ {% if prevrev %}<a href="{{ setrev(prevrev) }}">prev page</a>{% end %}
{% set nextrev = changesets[-1]['rev'] - 1 if changesets else None %}
- {% if nextrev > -1 %}<a href="?rev=rev({{ nextrev }})">next page</a>{% end %}
+ {% if nextrev > -1 %}<a href="{{ setrev(nextrev) }}">next page</a>{% end %}
<span style="color: #777;">
- hover things for a tooltip; red means slowest ever, green means fastest
- ever; first color and time means without .hg/cache, second means with
- .hg/cache.
+ hover things for a tooltip; red means slow, green means fast; first
+ color and time means without .hg/cache, second means with .hg/cache.
</span>
+ {% if local %}
+ local colors (<a href="{{ setlocal(None) }}">switch to global colors</a>)
+ {% else %}
+ global colors (<a href="{{ setlocal(1) }}">switch to local colors</a>)
+ {% end %}
</header>
<table>
<thead>
@@ -85,8 +89,8 @@
</table>
<footer>
<a href="/results.html">back to tip</a>
- {% if prevrev %}<a href="?rev=rev({{ prevrev }})">prev page</a>{% end %}
- {% if nextrev > -1 %}<a href="?rev=rev({{ nextrev }})">next page</a>{% end %}
+ {% if prevrev %}<a href="{{ setrev(prevrev) }}">prev page</a>{% end %}
+ {% if nextrev > -1 %}<a href="{{ setrev(nextrev) }}">next page</a>{% end %}
</footer>
</body>
</html>
--- a/viewer.py Wed May 27 18:57:30 2015 +0800
+++ b/viewer.py Thu May 28 15:11:01 2015 +0800
@@ -5,6 +5,7 @@
import re
import sqlite3
import subprocess
+from urllib import quote_plus
from tornado.ioloop import IOLoop
from tornado.options import define, options
@@ -133,10 +134,40 @@
self.write(line)
self.finish()
+ def urlencode(self, **kwargs):
+ def joinparams(params):
+ return ','.join(quote_plus(i, '()') for i in params)
+ return '&'.join(quote_plus(k) + '=' + joinparams(v) for k, v in kwargs.items())
+
+ def setlocal(self, value=None):
+ kwargs = self.request.arguments.copy()
+ if value is None:
+ try:
+ kwargs.pop('local')
+ except KeyError:
+ pass
+ else:
+ kwargs['local'] = [str(value)]
+ return '?' + self.urlencode(**kwargs)
+
+ def setrev(self, value):
+ kwargs = self.request.arguments.copy()
+ kwargs['rev'] = ['rev({})'.format(value)]
+ return '?' + self.urlencode(**kwargs)
+
def results_html(self):
changesets = self.getchangesets()
- results = self.getresults(changesets, self.get_argument('local', False))
- self.render('results.html', changesets=changesets, marks=MARKS, results=results)
+ local = self.get_argument('local', False)
+ results = self.getresults(changesets, local)
+ context = {
+ 'changesets': changesets,
+ 'marks': MARKS,
+ 'results': results,
+ 'local': local,
+ 'setlocal': self.setlocal,
+ 'setrev': self.setrev
+ }
+ self.render('results.html', **context)
def green_to_red((low, high), value):