Coverage for cc_modules/cc_reportschema.py: 74%

39 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-15 14:23 +0100

1""" 

2camcops_server/cc_modules/cc_reportschema.py 

3 

4=============================================================================== 

5 

6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

8 

9 This file is part of CamCOPS. 

10 

11 CamCOPS is free software: you can redistribute it and/or modify 

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

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

14 (at your option) any later version. 

15 

16 CamCOPS is distributed in the hope that it will be useful, 

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

18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

19 GNU General Public License for more details. 

20 

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

22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>. 

23 

24=============================================================================== 

25 

26**Common reports schema nodes.** 

27 

28""" 

29 

30from typing import Any, Dict 

31 

32from cardinal_pythonlib.colander_utils import BooleanNode 

33from colander import SchemaNode 

34 

35from camcops_server.cc_modules.cc_forms import RequestAwareMixin 

36 

37 

38DEFAULT_BY_YEAR = True 

39DEFAULT_BY_MONTH = True 

40DEFAULT_BY_DAY_OF_MONTH = False 

41DEFAULT_BY_TASK = True 

42DEFAULT_BY_USER = False 

43 

44 

45class ByYearSelector(BooleanNode, RequestAwareMixin): 

46 """ 

47 Split report by year? 

48 """ 

49 

50 def __init__(self, *args: Any, **kwargs: Any) -> None: 

51 super().__init__(*args, default=DEFAULT_BY_YEAR, **kwargs) 

52 

53 # noinspection PyUnusedLocal 

54 def after_bind(self, node: SchemaNode, kw: Dict[str, Any]) -> None: 

55 _ = self.gettext 

56 self.title = self.label = _("Split by year?") 

57 

58 

59class ByMonthSelector(BooleanNode, RequestAwareMixin): 

60 """ 

61 Split report by month? 

62 """ 

63 

64 def __init__(self, *args: Any, **kwargs: Any) -> None: 

65 super().__init__(*args, default=DEFAULT_BY_MONTH, **kwargs) 

66 

67 # noinspection PyUnusedLocal 

68 def after_bind(self, node: SchemaNode, kw: Dict[str, Any]) -> None: 

69 _ = self.gettext 

70 self.title = self.label = _("Split by month?") 

71 

72 

73class ByDayOfMonthSelector(BooleanNode, RequestAwareMixin): 

74 """ 

75 Split report by day of month? 

76 """ 

77 

78 def __init__(self, *args: Any, **kwargs: Any) -> None: 

79 super().__init__(*args, default=DEFAULT_BY_DAY_OF_MONTH, **kwargs) 

80 

81 # noinspection PyUnusedLocal 

82 def after_bind(self, node: SchemaNode, kw: Dict[str, Any]) -> None: 

83 _ = self.gettext 

84 self.title = self.label = _("Split by day of month?") 

85 

86 

87class ByTaskSelector(BooleanNode, RequestAwareMixin): 

88 """ 

89 Split report by task type? 

90 """ 

91 

92 def __init__(self, *args: Any, **kwargs: Any) -> None: 

93 super().__init__(*args, default=DEFAULT_BY_TASK, **kwargs) 

94 

95 # noinspection PyUnusedLocal 

96 def after_bind(self, node: SchemaNode, kw: Dict[str, Any]) -> None: 

97 _ = self.gettext 

98 self.title = self.label = _("Split by task type?") 

99 

100 

101class ByUserSelector(BooleanNode, RequestAwareMixin): 

102 """ 

103 Split report by user? 

104 """ 

105 

106 def __init__(self, *args: Any, **kwargs: Any) -> None: 

107 super().__init__(*args, default=DEFAULT_BY_USER, **kwargs) 

108 

109 # noinspection PyUnusedLocal 

110 def after_bind(self, node: SchemaNode, kw: Dict[str, Any]) -> None: 

111 _ = self.gettext 

112 self.title = self.label = _("Split by user?")