5
5
from .constants import ListRole , ListStatus , ReviewDecisionChoices
6
6
7
7
if TYPE_CHECKING :
8
- from .models import DestructionList
8
+ from .models import DestructionList , DestructionListAssignee
9
9
10
10
11
11
class State (Protocol ):
12
12
def assign_next (self , destruction_list : "DestructionList" ) -> None : ...
13
13
14
+ def reassign (self , destruction_list : "DestructionList" ) -> None : ...
15
+
14
16
15
17
class NewList :
16
18
def assign_next (self , destruction_list : "DestructionList" ) -> None :
@@ -23,8 +25,27 @@ def assign_next(self, destruction_list: "DestructionList") -> None:
23
25
destruction_list .set_status (ListStatus .ready_to_review )
24
26
destruction_list .assign (assignee )
25
27
28
+ def reassign (self , destruction_list : "DestructionList" ) -> None :
29
+ # When a list is new, it is assigned to the author. No action needed.
30
+ pass
31
+
26
32
27
33
class ReadyToReview :
34
+ def _deduce_next_reviewer (
35
+ self , destruction_list : "DestructionList"
36
+ ) -> "DestructionListAssignee" :
37
+ # Find the reviewers who have given fewer reviews
38
+ reviewers = destruction_list .assignees .filter (role = ListRole .reviewer ).annotate (
39
+ num_reviews = Count ("user__created_reviews" )
40
+ )
41
+ min_number_reviews = reviewers .aggregate (min_reviews = Min ("num_reviews" ))
42
+ next_reviewer = (
43
+ reviewers .filter (num_reviews = min_number_reviews ["min_reviews" ])
44
+ .order_by ("pk" )
45
+ .first ()
46
+ )
47
+ return next_reviewer
48
+
28
49
def assign_next (self , destruction_list : "DestructionList" ) -> None :
29
50
last_review = destruction_list .reviews .order_by ("created" ).last ()
30
51
if last_review and last_review .decision == ReviewDecisionChoices .rejected :
@@ -42,16 +63,11 @@ def assign_next(self, destruction_list: "DestructionList") -> None:
42
63
destruction_list .assign (destruction_list .get_author ())
43
64
return
44
65
45
- # Find the reviewers who have given fewer reviews
46
- reviewers = destruction_list .assignees .filter (role = ListRole .reviewer ).annotate (
47
- num_reviews = Count ("user__created_reviews" )
48
- )
49
- min_number_reviews = reviewers .aggregate (min_reviews = Min ("num_reviews" ))
50
- next_reviewer = (
51
- reviewers .filter (num_reviews = min_number_reviews ["min_reviews" ])
52
- .order_by ("pk" )
53
- .first ()
54
- )
66
+ next_reviewer = self ._deduce_next_reviewer (destruction_list )
67
+ destruction_list .assign (next_reviewer )
68
+
69
+ def reassign (self , destruction_list : "DestructionList" ) -> None :
70
+ next_reviewer = self ._deduce_next_reviewer (destruction_list )
55
71
destruction_list .assign (next_reviewer )
56
72
57
73
@@ -63,6 +79,10 @@ def assign_next(self, destruction_list: "DestructionList") -> None:
63
79
last_review = destruction_list .reviews .order_by ("created" ).last ()
64
80
destruction_list .assign (destruction_list .get_assignee (last_review .author ))
65
81
82
+ def reassign (self , destruction_list : "DestructionList" ) -> None :
83
+ # When a list has requested changes, it is assigned to the author. No action needed.
84
+ pass
85
+
66
86
67
87
class InternallyReviewed :
68
88
def assign_next (self , destruction_list : "DestructionList" ) -> None :
@@ -75,6 +95,10 @@ def assign_next(self, destruction_list: "DestructionList") -> None:
75
95
)
76
96
destruction_list .assign (archivist )
77
97
98
+ def reassign (self , destruction_list : "DestructionList" ) -> None :
99
+ # When a list has been internally reviewed, it is assigned to the author. No action needed.
100
+ pass
101
+
78
102
79
103
class ReadyForArchivist :
80
104
def assign_next (self , destruction_list : "DestructionList" ) -> None :
@@ -85,6 +109,10 @@ def assign_next(self, destruction_list: "DestructionList") -> None:
85
109
86
110
# TODO in the case where the archivist rejects it is not clear yet what should happen!
87
111
112
+ def reassign (self , destruction_list : "DestructionList" ) -> None :
113
+ # TODO
114
+ raise NotImplementedError
115
+
88
116
89
117
STATE_MANAGER = {
90
118
ListStatus .new : NewList (),
0 commit comments