Skip to content

Commit

Permalink
♻️ [#45] Use uuids instead of pk
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm authored and svenvandescheur committed Jun 11, 2024
1 parent 7cec1aa commit 93ce9c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions backend/src/openarchiefbeheer/zaken/api/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."),
Expand Down Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 93ce9c6

Please sign in to comment.