Skip to content

Commit f092150

Browse files
committed
✨ [#262] Added ordering on processing status
1 parent ad25495 commit f092150

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

backend/src/openarchiefbeheer/destruction/api/filtersets.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from django.db.models import QuerySet
1+
from django.db.models import Case, QuerySet, Value, When
2+
from django.utils.translation import gettext_lazy as _
23

34
from django_filters import FilterSet, NumberFilter, OrderingFilter, UUIDFilter
45

6+
from ..constants import InternalStatus
57
from ..models import (
68
DestructionList,
79
DestructionListItem,
@@ -12,9 +14,36 @@
1214

1315

1416
class DestructionListItemFilterset(FilterSet):
17+
destruction_list = UUIDFilter(
18+
field_name="destruction_list",
19+
method="filter_in_destruction_list",
20+
help_text=_(
21+
"Retrieve the items that are in a destruction list and "
22+
"order them based on processing status."
23+
),
24+
)
25+
1526
class Meta:
1627
model = DestructionListItem
17-
fields = ("destruction_list",)
28+
fields = ("destruction_list", "status", "processing_status")
29+
30+
def filter_in_destruction_list(
31+
self, queryset: QuerySet[DestructionListItem], name: str, value: str
32+
) -> QuerySet[DestructionListItem]:
33+
return (
34+
queryset.filter(destruction_list__uuid=value)
35+
.annotate(
36+
processing_status_index=Case(
37+
When(processing_status=InternalStatus.failed, then=Value(1)),
38+
When(processing_status=InternalStatus.processing, then=Value(2)),
39+
When(processing_status=InternalStatus.queued, then=Value(3)),
40+
When(processing_status=InternalStatus.new, then=Value(4)),
41+
When(processing_status=InternalStatus.succeeded, then=Value(5)),
42+
default=Value(1),
43+
),
44+
)
45+
.order_by("processing_status_index")
46+
)
1847

1948

2049
class DestructionListFilterset(FilterSet):

backend/src/openarchiefbeheer/destruction/api/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Meta:
111111
"status",
112112
"extra_zaak_data",
113113
"zaak_data",
114+
"processing_status",
114115
)
115116

116117
def validate(self, attrs: dict) -> dict:

0 commit comments

Comments
 (0)