Added pillar.web.utils.last_page_index()

This returns the last page number (base-1) of a paged Eve result.
This commit is contained in:
2017-01-19 15:13:01 +01:00
parent 129ec94608
commit 604d6c1a07
2 changed files with 35 additions and 0 deletions

View File

@@ -205,3 +205,24 @@ def is_valid_id(some_id):
return True
return False
def last_page_index(meta_info):
"""Eve pagination; returns the index of the last page.
:param meta_info: Eve's '_meta' response.
:returns: Eve page number (base-1) of the last page.
:rtype: int
"""
total = meta_info['total']
if total == 0:
return 1
per_page = meta_info['max_results']
pages = total // per_page
if total % per_page == 0:
return pages
return pages + 1