Coverage for src/ptf/display/utils.py: 61%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-05 09:56 +0000

1def paginate(rows, page, numfound): 

2 numpages = numfound // rows 

3 if numfound % rows: 

4 numpages += 1 

5 

6 # if page % 10 == 0: 

7 # fp = page - 10 + 1 

8 # else: 

9 # fp = (page/10) * 10 + 1 

10 # lp = fp + min(10, numpages - fp + 1) 

11 # next_slice = lp + ( numpages - lp ) / 2 

12 # previous_slice = fp / 2 

13 

14 if numpages < 10: 14 ↛ 18line 14 didn't jump to line 18 because the condition on line 14 was always true

15 fp = 1 

16 lp = numpages 

17 previous_slice = next_slice = 0 

18 elif page < 5: 

19 fp = 1 

20 lp = min(numpages, 9) 

21 previous_slice = 0 

22 next_slice = lp + ((numpages - lp) // 2) 

23 else: 

24 fp = page - 4 

25 lp = min(numpages, page + 4) 

26 previous_slice = fp // 2 

27 next_slice = lp + ((numpages - lp) // 2) 

28 

29 template_data = { 

30 "curpage": page, 

31 "pagerange": list(range(fp, lp + 1)), 

32 "previous_slice": previous_slice, 

33 "next_slice": next_slice, 

34 "numpages": numpages, 

35 } 

36 return template_data 

37 

38 

39def paginate_from_request(request, params, numfound): 

40 """ 

41 prepare le context pour la pagination 

42 et supprime la pagination si il y a en a une sur la query 

43 @return: context 

44 """ 

45 rows = params["rows"] 

46 page = params["page"] 

47 context = paginate(rows, page, numfound) 

48 

49 context["page_path"] = params["path"] 

50 return context