Is there any best practice for pagination with Pony ORM?
I'm seeing others have these has_next
and has_previous
helper methods but in Pony I'm on my own.
So far this is what I have, a couple of Jinja helpers:
# Jinja helpers for pagination
def next_page(current, max_page):
if current >= max_page:
return False
else:
return current + 1
def prev_page(current, max_page):
if current < 2:
return False
else:
return current - 1
max_page
is calculated like this: math.ceil(MyTable.select().count()/PAGE_SIZE)
But gets a little tedious, you have to keep sending current page and max page all around.
{% if maxpage > 1 %}
{% if prev_page(page, maxpage) %}
<a href="{{ url_for('index', pagenum=prev_page(page, maxpage)) }}"><</a>
{% endif %}
{% if next_page(page, maxpage) %}
<a href="{{ url_for('index', pagenum=next_page(page, maxpage)) }}">></a>
{% endif %}
{% endif %}
So am I missing something? Any better way?