Skip to content

Commit ee3dc9e

Browse files
committed
✨ [#234] Add filtering on review
1 parent 21566f3 commit ee3dc9e

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from rest_framework import serializers
44
from rest_framework_gis.fields import GeometryField
55

6-
from openarchiefbeheer.destruction.models import DestructionList
6+
from openarchiefbeheer.destruction.models import DestructionList, DestructionListReview
77

88
from ..models import Zaak
99

@@ -94,5 +94,11 @@ class ZaakTypeChoicesQueryParamSerializer(serializers.Serializer):
9494
destruction_list = serializers.SlugRelatedField(
9595
slug_field="uuid",
9696
required=False,
97-
queryset=DestructionList.objects.all().prefetch_related("items", "items__zaak"),
97+
queryset=DestructionList.objects.all().prefetch_related("items__zaak"),
98+
)
99+
review = serializers.PrimaryKeyRelatedField(
100+
required=False,
101+
queryset=DestructionListReview.objects.all().prefetch_related(
102+
"item_reviews__destruction_list_item__zaak",
103+
),
98104
)

backend/src/openarchiefbeheer/zaken/api/views.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ..tasks import retrieve_and_cache_zaken_from_openzaak
1818
from ..utils import (
1919
get_zaaktypen_choices_from_list,
20+
get_zaaktypen_choices_from_review,
2021
retrieve_selectielijstklasse_choices,
2122
retrieve_zaaktypen_choices,
2223
)
@@ -70,6 +71,8 @@ def get(self, request, *args, **kwargs):
7071

7172
if destruction_list := param_serializer.validated_data.get("destruction_list"):
7273
zaaktypen_choices = get_zaaktypen_choices_from_list(destruction_list)
74+
elif review := param_serializer.validated_data.get("review"):
75+
zaaktypen_choices = get_zaaktypen_choices_from_review(review)
7376
else:
7477
zaaktypen_choices = retrieve_zaaktypen_choices()
7578

backend/src/openarchiefbeheer/zaken/utils.py

+32-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
from .types import DropDownChoice
2626

2727
if TYPE_CHECKING:
28-
from openarchiefbeheer.destruction.models import DestructionList
28+
from openarchiefbeheer.destruction.models import (
29+
DestructionList,
30+
DestructionListReview,
31+
)
2932

3033

3134
def pagination_helper(
@@ -112,25 +115,44 @@ def retrieve_zaaktypen_choices() -> list[DropDownChoice]:
112115
return sorted(zaaktypen_choices, key=lambda zaaktype: zaaktype["label"])
113116

114117

115-
def get_zaaktypen_choices_from_list(
116-
destruction_list: "DestructionList",
117-
) -> list[DropDownChoice]:
118-
items_qs = destruction_list.items.filter(status=ListItemStatus.suggested).distinct(
119-
"zaak__zaaktype"
120-
)
121-
zaaktypen_to_include = items_qs.values_list(
122-
"zaak__zaaktype", "zaak___expand__zaaktype__identificatie"
123-
)
118+
def _get_zaaktype_choices(zaaktypen_to_include: dict[list]) -> list[DropDownChoice]:
119+
"""Return formatted zaaktype choices
124120
121+
Takes a dictionary where the key is the identificatie of a zaaktype and
122+
the value is a list of all the URLs for the different versions of that zaaktype."""
125123
zaaktypen = defaultdict(list)
126124
for zaaktype_url, zaaktype_identificatie in zaaktypen_to_include:
127125
zaaktypen[zaaktype_identificatie].append(zaaktype_url)
126+
128127
zaaktypen_choices = [
129128
{"label": key, "value": ",".join(value)} for key, value in zaaktypen.items()
130129
]
131130
return sorted(zaaktypen_choices, key=lambda zaaktype: zaaktype["label"])
132131

133132

133+
def get_zaaktypen_choices_from_list(
134+
destruction_list: "DestructionList",
135+
) -> list[DropDownChoice]:
136+
zaaktypen_to_include = (
137+
destruction_list.items.filter(status=ListItemStatus.suggested)
138+
.distinct("zaak__zaaktype")
139+
.values_list("zaak__zaaktype", "zaak___expand__zaaktype__identificatie")
140+
)
141+
return _get_zaaktype_choices(zaaktypen_to_include)
142+
143+
144+
def get_zaaktypen_choices_from_review(
145+
review: "DestructionListReview",
146+
) -> list[DropDownChoice]:
147+
zaaktypen_to_include = review.item_reviews.distinct(
148+
"destruction_list_item__zaak__zaaktype"
149+
).values_list(
150+
"destruction_list_item__zaak__zaaktype",
151+
"destruction_list_item__zaak___expand__zaaktype__identificatie",
152+
)
153+
return _get_zaaktype_choices(zaaktypen_to_include)
154+
155+
134156
def format_selectielijstklasse_choice(resultaat: Resultaat) -> DropDownChoice:
135157
description = f"{resultaat.get('volledig_nummer', resultaat['nummer'])} - {resultaat['naam']} - {resultaat['waardering']}"
136158
if resultaat.get("bewaartermijn"):

0 commit comments

Comments
 (0)