Coverage for src/utils/paginator.py : 100%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from sqlalchemy import func
2import math
4from settings import PAGE_SIZE
7class Paginator:
8 @staticmethod
9 def get_from(query, page_number=1):
10 page_size = PAGE_SIZE
11 offset = (page_number - 1) * page_size
13 total_elem = query.count()
14 if offset < 0:
15 return [], math.ceil(total_elem / page_size)
17 datas = query.offset(offset).limit(page_size).all()
19 return datas, math.ceil(total_elem / page_size)