From 8e606499c90921d166ee9961441e65b8961bf124 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 18 Dec 2019 18:49:15 +0000 Subject: [PATCH] Add pager to property page --- app.py | 15 ++++++++++++--- templates/property.html | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index fff4ecc..429725a 100755 --- a/app.py +++ b/app.py @@ -187,10 +187,17 @@ def property_query_page(property_id): .group_by(Triple.object_id) .order_by(desc('c'))) - labels = get_labels_db({f'Q{object_id}' for object_id, c in q}) + page = utils.get_int_arg('page') or 1 + total = q.count() + page_size = 50 + pager = Pagination(page, page_size, total) + + page_hits = pager.slice(q) + + labels = get_labels_db({f'Q{object_id}' for object_id, c in page_hits}) hits = [] - for object_id, count in q: + for object_id, count in page_hits: qid = f'Q{object_id}' hits.append({'qid': qid, 'label': labels.get(qid) or '[item missing]', @@ -200,6 +207,8 @@ def property_query_page(property_id): label=g.title, order=('name' if sort_by_name else 'count'), pid=pid, + page=page, + pager=pager, hits=hits) @app.route('/') @@ -833,7 +842,7 @@ def browse_page(): cache_refreshed = True item.image = detail[image_filename] - return render_template('new_find_more.html', + return render_template('find_more.html', page=page, label=g.title, pager=pager, diff --git a/templates/property.html b/templates/property.html index 19208d3..86370ae 100644 --- a/templates/property.html +++ b/templates/property.html @@ -1,3 +1,4 @@ +{% from "macro.html" import render_pagination %} {% extends "base.html" %} {% block title %}{{ label }}{% endblock %} @@ -16,7 +17,9 @@ {% endif %}

-

Total: {{ hits | length }}

+

Total: {{ '{:,d}'.format(pager.total_count) }}

+ + {{ render_pagination(pager) }} + + {{ render_pagination(pager) }} + {% endblock %}