|
7 | 7 | from rest_framework import status
|
8 | 8 | from rest_framework.exceptions import ValidationError
|
9 | 9 | from rest_framework.permissions import IsAdminUser, IsAuthenticated
|
| 10 | +from rest_framework.request import Request |
10 | 11 | from rest_framework.response import Response
|
11 | 12 | from rest_framework.views import APIView
|
12 | 13 |
|
@@ -193,6 +194,37 @@ def get(self, request, *args, **kwargs):
|
193 | 194 | class InformatieobjecttypeChoicesView(FilterOnZaaktypeMixin, APIView):
|
194 | 195 | permission_classes = [IsAuthenticated]
|
195 | 196 |
|
| 197 | + # TODO |
| 198 | + # Remove once https://github.com/open-zaak/open-zaak/issues/1939 is fixed |
| 199 | + def get_query_params(self, request: Request) -> HashableDict: |
| 200 | + """ |
| 201 | + We need to filter the informatieobjecttypen on zaaktype URL, but we only have the identificatie. |
| 202 | + The identificatie can represent multiple versions of the zaaktype (multiple URLs). |
| 203 | + As a bandaid fix, we use the URL of the latest version (highest begin_geldigheid field). |
| 204 | + """ |
| 205 | + query_params = HashableDict() |
| 206 | + if not request.GET.get("zaaktype_identificatie"): |
| 207 | + return query_params |
| 208 | + |
| 209 | + serializer = ZaaktypeFilterSerializer(data=request.query_params) |
| 210 | + serializer.is_valid(raise_exception=True) |
| 211 | + |
| 212 | + zaaktypen_query_params = HashableDict() |
| 213 | + zaaktypen_query_params.update( |
| 214 | + {"identificatie": serializer.validated_data["zaaktype_identificatie"]} |
| 215 | + ) |
| 216 | + zaaktypen = retrieve_zaaktypen(zaaktypen_query_params) |
| 217 | + if not zaaktypen: |
| 218 | + return query_params |
| 219 | + |
| 220 | + # Sort in descending order, so that the zaaktype with the most recent begin date is first. (Latest zaaktype version) |
| 221 | + zaaktypen = sorted( |
| 222 | + zaaktypen, key=lambda zaaktype: zaaktype["begin_geldigheid"], reverse=True |
| 223 | + ) |
| 224 | + query_params.update({"zaaktype": zaaktypen[0]["url"]}) |
| 225 | + |
| 226 | + return query_params |
| 227 | + |
196 | 228 | @extend_schema(
|
197 | 229 | summary=_("Retrieve informatieobjecttypen choices"),
|
198 | 230 | description=_(
|
|
0 commit comments