Coverage for bundesliga_tippspiel/jinja_extras.py: 54%

Shortcuts 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

32 statements  

1"""LICENSE 

2Copyright 2017 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of bundesliga-tippspiel. 

5 

6bundesliga-tippspiel is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11bundesliga-tippspiel is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with bundesliga-tippspiel. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20from typing import Dict, Any 

21from bundesliga_tippspiel.utils.matchday import get_matchday_info, \ 

22 get_selected_league 

23 

24 

25def jinja_extras() -> Dict[str, Any]: 

26 """ 

27 Makes sure that jinja has access to these variables 

28 :return: The variables to forward to jinja 

29 """ 

30 return { 

31 "get_pill_class": get_pill_class, 

32 "get_matchday_total_pill_class": get_matchday_total_pill_class, 

33 "get_matchday_info": get_matchday_info, 

34 "get_selected_league": get_selected_league 

35 } 

36 

37 

38def get_pill_class(points: int) -> str: 

39 """ 

40 Calculates the appropriate pill badge for an amount of points 

41 :param points: The points for which to get the pill class 

42 :return: The appropriate pill badge class 

43 """ 

44 if points == 0: 

45 return "danger" 

46 elif points <= 3: 

47 return "warning" 

48 elif points <= 7: 48 ↛ 49line 48 didn't jump to line 49, because the condition on line 48 was never true

49 return "light" 

50 elif points <= 10: 

51 return "info" 

52 elif points <= 12: 

53 return "primary" 

54 elif points > 12: 54 ↛ 57line 54 didn't jump to line 57, because the condition on line 54 was never false

55 return "success" 

56 else: 

57 return "secondary" 

58 

59 

60def get_matchday_total_pill_class(points: int) -> str: 

61 """ 

62 Calculates the appropriate pill badge for an amount of points on a matchday 

63 :param points: The points for which to get the pill class 

64 :return: The appropriate pill badge class 

65 """ 

66 if points == 0: 66 ↛ 68line 66 didn't jump to line 68, because the condition on line 66 was never false

67 return "danger" 

68 elif points <= 20: 

69 return "warning" 

70 elif points <= 40: 

71 return "light" 

72 elif points <= 60: 

73 return "info" 

74 elif points <= 80: 

75 return "primary" 

76 elif points > 100: 

77 return "success" 

78 else: 

79 return "secondary"