Hide keyboard shortcuts

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 

3 

4from settings import PAGE_SIZE 

5 

6 

7class Paginator: 

8 @staticmethod 

9 def get_from(query, page_number=1): 

10 page_size = PAGE_SIZE 

11 offset = (page_number - 1) * page_size 

12 

13 total_elem = query.count() 

14 if offset < 0: 

15 return [], math.ceil(total_elem / page_size) 

16 

17 datas = query.offset(offset).limit(page_size).all() 

18 

19 return datas, math.ceil(total_elem / page_size)