Add pager to property page

This commit is contained in:
Edward Betts 2019-12-18 18:49:15 +00:00
parent 19c6d3b81c
commit 8e606499c9
2 changed files with 19 additions and 4 deletions

15
app.py
View file

@ -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,

View file

@ -1,3 +1,4 @@
{% from "macro.html" import render_pagination %}
{% extends "base.html" %}
{% block title %}{{ label }}{% endblock %}
@ -16,7 +17,9 @@
{% endif %}
</p>
<p>Total: {{ hits | length }}</p>
<p>Total: {{ '{:,d}'.format(pager.total_count) }}</p>
{{ render_pagination(pager) }}
<ul>
{% for hit in hits %}
@ -31,6 +34,9 @@
</li>
{% endfor %}
</ul>
{{ render_pagination(pager) }}
</div>
{% endblock %}