From 190bed10ac07b3aeae71d0f12ee6236fe909abfc Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Fri, 7 Jun 2024 09:57:06 +0200 Subject: [PATCH] :recycle: [#45] Use uuids instead of pk --- .../openarchiefbeheer/zaken/api/filtersets.py | 17 +++++++++++------ .../zaken/tests/test_viewsets.py | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/src/openarchiefbeheer/zaken/api/filtersets.py b/backend/src/openarchiefbeheer/zaken/api/filtersets.py index aad99900..360bb338 100644 --- a/backend/src/openarchiefbeheer/zaken/api/filtersets.py +++ b/backend/src/openarchiefbeheer/zaken/api/filtersets.py @@ -12,7 +12,13 @@ ) from django.utils.translation import gettext_lazy as _ -from django_filters import BooleanFilter, CharFilter, FilterSet, NumberFilter +from django_filters import ( + BooleanFilter, + CharFilter, + FilterSet, + NumberFilter, + UUIDFilter, +) from openarchiefbeheer.destruction.constants import ListItemStatus from openarchiefbeheer.destruction.models import DestructionListItem @@ -28,14 +34,13 @@ class ZaakFilter(FilterSet): "If True, only cases not already included in a destruction list are returned." ), ) - not_in_destruction_list_except = NumberFilter( + not_in_destruction_list_except = UUIDFilter( field_name="not_in_destruction_list_except", method="filter_not_in_destruction_list_except", help_text=_( "Only cases not already included in a destruction list except the one specified are returned. " "The cases that are included in the 'exception' list are returned first." ), - decimal_places=0, ) _expand__resultaat__resultaattype = CharFilter( help_text=_("Filter on the exact URL of resultaattype."), @@ -149,14 +154,14 @@ def filter_not_in_destruction_list( return queryset.exclude(url__in=Subquery(zaken_to_exclude)) def filter_not_in_destruction_list_except( - self, queryset: QuerySet[Zaak], name: str, value: int + self, queryset: QuerySet[Zaak], name: str, value: str ): zaken_to_exclude = DestructionListItem.objects.filter( - ~Q(status=ListItemStatus.removed) & ~Q(destruction_list=value) + ~Q(status=ListItemStatus.removed) & ~Q(destruction_list__uuid=value) ).values_list("zaak", flat=True) exception_list = DestructionListItem.objects.filter( - destruction_list=value + destruction_list__uuid=value ).values_list("zaak", flat=True) return ( diff --git a/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py b/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py index 92b4ace6..6ee26e67 100644 --- a/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py +++ b/backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py @@ -273,7 +273,7 @@ def test_filter_out_zaken_already_in_destruction_lists_except_one(self): user = UserFactory(username="record_manager", role__can_start_destruction=True) endpoint = furl(reverse("api:zaken-list")) - endpoint.args["not_in_destruction_list_except"] = item.destruction_list.pk + endpoint.args["not_in_destruction_list_except"] = item.destruction_list.uuid self.client.force_authenticate(user) response = self.client.get(endpoint.url)