Coverage for cc_modules/cc_reportschema.py: 76%

33 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-08 23:14 +0000

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/cc_modules/cc_reportschema.py 

5 

6=============================================================================== 

7 

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

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

10 

11 This file is part of CamCOPS. 

12 

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

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

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

16 (at your option) any later version. 

17 

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

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

20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

21 GNU General Public License for more details. 

22 

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

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

25 

26=============================================================================== 

27 

28**Common reports schema nodes.** 

29 

30""" 

31 

32from typing import Any, Dict 

33 

34from cardinal_pythonlib.colander_utils import BooleanNode 

35from colander import SchemaNode 

36 

37from camcops_server.cc_modules.cc_forms import RequestAwareMixin 

38 

39 

40DEFAULT_BY_YEAR = True 

41DEFAULT_BY_MONTH = True 

42DEFAULT_BY_TASK = True 

43DEFAULT_BY_USER = False 

44 

45 

46class ByYearSelector(BooleanNode, RequestAwareMixin): 

47 """ 

48 Split report by year? 

49 """ 

50 

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

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

53 

54 # noinspection PyUnusedLocal 

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

56 _ = self.gettext 

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

58 

59 

60class ByMonthSelector(BooleanNode, RequestAwareMixin): 

61 """ 

62 Split report by month? 

63 """ 

64 

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

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

67 

68 # noinspection PyUnusedLocal 

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

70 _ = self.gettext 

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

72 

73 

74class ByTaskSelector(BooleanNode, RequestAwareMixin): 

75 """ 

76 Split report by task type? 

77 """ 

78 

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

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

81 

82 # noinspection PyUnusedLocal 

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

84 _ = self.gettext 

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

86 

87 

88class ByUserSelector(BooleanNode, RequestAwareMixin): 

89 """ 

90 Split report by user? 

91 """ 

92 

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

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

95 

96 # noinspection PyUnusedLocal 

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

98 _ = self.gettext 

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