# HG changeset patch # User Daniele Nicolodi # Date 1309300767 -7200 # Node ID aa8b0bb724f69521283f2aa26437656fb9cb3066 # Parent e71a85df59e048215ef1540ae64e4edb197b2e8a Some polish to pagination and database browsing code. diff -r e71a85df59e0 -r aa8b0bb724f6 src/ltpdarepo/__init__.py --- a/src/ltpdarepo/__init__.py Mon Jun 27 21:05:24 2011 +0200 +++ b/src/ltpdarepo/__init__.py Wed Jun 29 00:39:27 2011 +0200 @@ -74,6 +74,14 @@ return '' +def url_for_other_page(page): + args = request.view_args.copy() + args.update(request.args) + args.update(p=page) + return url_for(request.endpoint, **args) +app.jinja_env.globals['url_for_other_page'] = url_for_other_page + + @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': diff -r e71a85df59e0 -r aa8b0bb724f6 src/ltpdarepo/pagination.py --- a/src/ltpdarepo/pagination.py Mon Jun 27 21:05:24 2011 +0200 +++ b/src/ltpdarepo/pagination.py Wed Jun 29 00:39:27 2011 +0200 @@ -1,8 +1,8 @@ from math import ceil, floor class Pagination(object): - def __init__(self, current, size, count, items=9): - self.current = current + def __init__(self, page=1, count=10, size=10, items=9): + self.current = page self.size = size self.count = count self.items = items @@ -24,8 +24,9 @@ return self.current < self.pages @property - def limits(self): - return ((self.current - 1) * self.size, self.size) + def slice(self): + start = (self.current - 1) * self.size + return slice(start, start + self.size) def __iter__(self): # cache number of pages diff -r e71a85df59e0 -r aa8b0bb724f6 src/ltpdarepo/templates/browse.html --- a/src/ltpdarepo/templates/browse.html Mon Jun 27 21:05:24 2011 +0200 +++ b/src/ltpdarepo/templates/browse.html Wed Jun 29 00:39:27 2011 +0200 @@ -18,6 +18,7 @@ {% if not objs %}

{% else %} +

{{ batch.count }} objects

@@ -43,9 +44,9 @@ {% endfor %}
-{% import "pagination.html" as p %} +{% import "pagination.html" as pagination %} {% if pagination is defined %} -{{ p.render(pagination) }} +{{ pagination.render(batch) }} {% endif %} {% endif %} {% endblock %} diff -r e71a85df59e0 -r aa8b0bb724f6 src/ltpdarepo/templates/query.html --- a/src/ltpdarepo/templates/query.html Mon Jun 27 21:05:24 2011 +0200 +++ b/src/ltpdarepo/templates/query.html Wed Jun 29 00:39:27 2011 +0200 @@ -66,6 +66,7 @@ {% if objs %} +

{{ batch.count }} objects

diff -r e71a85df59e0 -r aa8b0bb724f6 src/ltpdarepo/templates/query/index.html --- a/src/ltpdarepo/templates/query/index.html Mon Jun 27 21:05:24 2011 +0200 +++ b/src/ltpdarepo/templates/query/index.html Wed Jun 29 00:39:27 2011 +0200 @@ -2,7 +2,7 @@ {% block title %} Queries {% endblock %} {% block body %}

Queries

-

Manage queries for database &llaquo;{{ database }}&rlaquo;:

+

Queries for database «{{ database }}»