Mercurial > hg > ltpdarepo
changeset 155:498ed3c29a0a
Allow user to alter pagination size in object listings.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Thu, 03 Nov 2011 20:30:46 +0100 |
parents | 2429e9db4f34 |
children | f6f93996acf4 |
files | src/ltpdarepo/__init__.py src/ltpdarepo/static/style.css src/ltpdarepo/templates/browse.html src/ltpdarepo/templates/objs.html src/ltpdarepo/templates/pagination.html src/ltpdarepo/views/browse.py |
diffstat | 6 files changed, 57 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ltpdarepo/__init__.py Wed Oct 26 20:13:12 2011 +0200 +++ b/src/ltpdarepo/__init__.py Thu Nov 03 20:30:46 2011 +0100 @@ -98,6 +98,14 @@ app.jinja_env.globals['url_for_other_order'] = url_for_other_order +def url_for_other_size(size): + args = request.view_args.copy() + args.update(request.args) + args.update(n=size) + return url_for(request.endpoint, **args) +app.jinja_env.globals['url_for_other_size'] = url_for_other_size + + def is_safe_url(target): ref = urlparse(request.host_url) test = urlparse(urljoin(request.host_url, target))
--- a/src/ltpdarepo/static/style.css Wed Oct 26 20:13:12 2011 +0200 +++ b/src/ltpdarepo/static/style.css Thu Nov 03 20:30:46 2011 +0100 @@ -327,12 +327,32 @@ /* pagination */ -.pagination { +.count { + float: left; + font-size: 90%; +} + +.count a, .count span { + text-align: center; + text-decoration: none; + color: #888; + display: inline-block; + float: left; + padding: 0px; + margin: 5px; + border-bottom: 1px solid white; +} + +.count a { + padding: 0 0.5em; +} + +.pages { float: right; font-size: 90%; } -.pagination a, .pagination span { +.pages a, .pages span { text-align: center; text-decoration: none; color: #888; @@ -344,7 +364,7 @@ border-bottom: 1px solid white; } -.pagination a:hover { +.pages a:hover, .count a:hover { border-bottom: 1px solid #888; } @@ -474,7 +494,6 @@ .query { font-size: 90%; - margin: 0.5em 0; } /* select elements are replaced with js equivalents. avoid jumpiness */
--- a/src/ltpdarepo/templates/browse.html Wed Oct 26 20:13:12 2011 +0200 +++ b/src/ltpdarepo/templates/browse.html Thu Nov 03 20:30:46 2011 +0100 @@ -1,1 +1,2 @@ {% extends "objs.html" %} +{% block above %}<p class="discrete"> </p>{% endblock %}
--- a/src/ltpdarepo/templates/objs.html Wed Oct 26 20:13:12 2011 +0200 +++ b/src/ltpdarepo/templates/objs.html Thu Nov 03 20:30:46 2011 +0100 @@ -4,8 +4,6 @@ {% block body %} <h2>{% block pagetitle %}Database «{{ database.id }}»{% endblock %}</h2> <p class="discrete">{{ database.description }}</p> -<p class="discrete">{{ batch.count }} objects</p> - {% block above %}{% endblock %} {% if objs %} {{ pagination.render(batch) }}
--- a/src/ltpdarepo/templates/pagination.html Wed Oct 26 20:13:12 2011 +0200 +++ b/src/ltpdarepo/templates/pagination.html Thu Nov 03 20:30:46 2011 +0100 @@ -1,5 +1,16 @@ {% macro render(pagination) %} - <div class="pagination wrapper"> +<div class="pagination wrapper"> + <div class="count"> + {% if pagination.count > pagination.size %} + <span>{{ pagination.size }} of {{ pagination.count }} objects</span> + <a href="{{ url_for_other_size(pagination.size * 2) }}">more</a> + <a href="{{ url_for_other_size(pagination.size // 2) }}">less</a> + {% else %} + <span>{{ pagination.count }} objects</span> + <a href="{{ url_for_other_size(pagination.size // 2) }}">less</a> + {% endif %} + </div> + <div class="pages"> {% if pagination.has_prev %} <a class="prev" href="{{ url_for_other_page(pagination.current - 1) }}" alt="prev">«</a> {% else %} @@ -22,4 +33,5 @@ <span class="next discrete">»</span> {% endif %} </div> +</div> {% endmacro %}
--- a/src/ltpdarepo/views/browse.py Wed Oct 26 20:13:12 2011 +0200 +++ b/src/ltpdarepo/views/browse.py Thu Nov 03 20:30:46 2011 +0100 @@ -28,7 +28,7 @@ MORE = ('version', 'ip', 'hostname', 'os', 'validated', 'vdate') TIMESERIESFIELDS = ('id', 'name', 't0', 'nsecs', 'quantity', 'keywords', 'title', 'description') -PAGESIZE = 20 +PAGESIZE = 64 class Objs(object): @@ -314,6 +314,12 @@ return order, reverse @property + def pagesize(self): + """Current page size in a paginated view""" + # validation by conversion to int + return self.formdata.get('n', PAGESIZE, type=int) + + @property def page(self): """Current page in a paginated view""" # validation by conversion to int @@ -416,7 +422,7 @@ r = Request(request.args, Objs.columns) count = Objs(database).count() - batch = Pagination(r.page, size=PAGESIZE, count=count) + batch = Pagination(r.page, size=r.pagesize, count=count) objs = Objs(database).orderby(*r.order).limit(*batch.limits).all() return render_template('browse.html', objs=objs, batch=batch, @@ -489,7 +495,7 @@ # collect objects count = Objs(database).filter('name LIKE %s', q).count() - batch = Pagination(r.page, size=PAGESIZE, count=count) + batch = Pagination(r.page, size=r.pagesize, count=count) objs = Objs(database).filter('name LIKE %s', q).orderby(*r.order).limit(*batch.limits).all() return render_template('browse.html', objs=objs, batch=batch, @@ -513,7 +519,7 @@ # collect objects count = Objs(database).filter(*r.query).count() - batch = Pagination(r.page, size=PAGESIZE, count=count) + batch = Pagination(r.page, size=r.pagesize, count=count) objs = Objs(database).filter(*r.query).orderby(*r.order).limit(*batch.limits).all() return render_template('query.html', objs=objs, batch=batch, @@ -545,7 +551,7 @@ # collect objects count = Objs(database).filter(*r.query).count() - batch = Pagination(r.page, size=PAGESIZE, count=count) + batch = Pagination(r.page, size=r.pagesize, count=count) objs = Objs(database).filter(*r.query).orderby(*r.order).limit(*batch.limits).all() return render_template('namedquery.html', objs=objs, batch=batch, @@ -571,7 +577,7 @@ # collect objects count = Timeseries(database).filter(*r.query).timespan(*t.range).count() - batch = Pagination(r.page, size=PAGESIZE, count=count) + batch = Pagination(r.page, size=r.pagesize, count=count) objs = Timeseries(database).filter(*r.query).timespan(*t.range).orderby(*r.order).limit(*batch.limits).all() return render_template('timerange.html', objs=objs, batch=batch,