Coverage for src/mesh/views/components/submission_list.py: 91%

32 statements  

« prev     ^ index     » next       coverage.py v7.7.0, created at 2025-04-28 07:45 +0000

1from __future__ import annotations 

2 

3from dataclasses import dataclass, field 

4from enum import Enum, unique 

5from typing import Literal 

6 

7from django.utils.translation import gettext_lazy as _ 

8 

9from ...model.submission_status import SubmissionStatus, SubmissionStatusType 

10from ...models.submission_models import SubmissionState 

11 

12 

13@unique 

14class SubmissionListEnum(Enum): 

15 ALL = "ALL" 

16 

17 

18SubmissionListType = Literal[SubmissionListEnum.ALL,] 

19 

20 

21@dataclass 

22class SubmissionListConfig: 

23 """ 

24 Config used by the submission_list view. 

25 

26 The available submissions are grouped in different tables according to the 

27 submission status wrt. the user role. 

28 This object defines rules about how to display/handle one of these submission group and 

29 holds the submission data. 

30 """ 

31 

32 key: SubmissionStatusType | SubmissionListType 

33 title: str 

34 # All the submissions for this submission status 

35 all_submissions: list = field(default_factory=list) 

36 # The active submissions to be displayed (for ex. the filtered submissions) 

37 submissions: list = field(default_factory=list) 

38 # Whether to display the corresponding submission table 

39 display: bool = field(default=True) 

40 # HTML fragment to display when `display=False` 

41 display_html: str = field(default="") 

42 # Whether to use these submissions with filters ie. whether to use them 

43 # to populate the filters & whether to filter them. 

44 in_filters: bool = field(default=True) 

45 # String of classes (space separated) to be appended to the submission table 

46 html_classes: str = field(default="") 

47 

48 @property 

49 def id(self) -> str: 

50 return f"submission-table-{self.key.value}" 

51 

52 

53def get_submission_list_config() -> list[SubmissionListConfig]: 

54 """ 

55 Returns the config to display the submissions for the user role. 

56 """ 

57 return [ 

58 SubmissionListConfig( 

59 key=SubmissionStatus.TODO, title=_("Requires action"), html_classes="todo" 

60 ), 

61 SubmissionListConfig( 

62 key=SubmissionStatus.WAITING, 

63 title=_("Waiting for other's input"), 

64 html_classes="waiting", 

65 ), 

66 SubmissionListConfig( 

67 key=SubmissionStatus.DONE, 

68 title=_("Done"), 

69 html_classes="done", 

70 ), 

71 ] 

72 

73 

74def get_done_submission_list_config() -> list[SubmissionListConfig]: 

75 """ 

76 Returns the config to display only the done submissions. 

77 """ 

78 return [ 

79 SubmissionListConfig( 

80 key=SubmissionStatus.DONE, 

81 title=_("Done"), 

82 html_classes="done", 

83 ), 

84 ] 

85 

86 

87def get_all_submission_list_config() -> list[SubmissionListConfig]: 

88 """ 

89 Returns the config to display all the submissions in 1 list. 

90 """ 

91 

92 return [ 

93 SubmissionListConfig( 

94 key=SubmissionListEnum.ALL, 

95 title=_("All"), 

96 html_classes="waiting", 

97 ), 

98 ] 

99 

100 

101def get_submission_by_state_config() -> list[SubmissionListConfig]: 

102 """ 

103 Returns the config to display the submissions for the user role. 

104 """ 

105 return [ 

106 SubmissionListConfig(key=SubmissionState.OPENED, title=_("Draft"), html_classes="waiting"), 

107 SubmissionListConfig( 

108 key=SubmissionState.ON_REVIEW, title=_("Under review"), html_classes="waiting" 

109 ), 

110 SubmissionListConfig( 

111 key=SubmissionState.REVISION_REQUESTED, 

112 title=_("Revision requested"), 

113 html_classes="waiting", 

114 ), 

115 SubmissionListConfig( 

116 key=SubmissionState.REVISION_SUBMITTED, 

117 title=_("Revision submitted"), 

118 html_classes="waiting", 

119 ), 

120 SubmissionListConfig( 

121 key=SubmissionState.ACCEPTED, title=_("Accepted"), html_classes="waiting" 

122 ), 

123 SubmissionListConfig( 

124 key=SubmissionState.REJECTED, title=_("Rejected"), html_classes="waiting" 

125 ), 

126 ]