Skip to content

Commit

Permalink
✨ Allow filtering on zaaktype omschrijving
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed May 16, 2024
1 parent 6f25182 commit ef67588
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions backend/src/openarchiefbeheer/zaken/api/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
from ..models import Zaak


class ExpandFilter(CharFilter):
"""
Custom filter looking for `field_name` and `lookup_expr` within _expand.
"""

def filter(self, qs, value):
if value:
lookup = f"_expand__{self.field_name}__{self.lookup_expr}"
qs = qs.filter(**{lookup: value})
return qs


class ZaakFilter(FilterSet):
not_in_destruction_list = BooleanFilter(
field_name="not_in_destruction_list",
Expand Down Expand Up @@ -49,6 +61,10 @@ class ZaakFilter(FilterSet):
),
)

zaaktype__omschrijving__icontains = ExpandFilter(
field_name="zaaktype__omschrijving", lookup_expr="icontains"
)

class Meta:
model = Zaak
fields = {
Expand Down
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/zaken/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Params:
"zaaktype": {
"url": "http://catalogue-api.nl/zaaktypen/111-111-111",
"selectielijst_procestype": {"nummer": 1},
"omschrijving": "Aangifte behandelen",
},
"resultaat": {
"resultaattype": "http://catalogue-api.nl/catalogi/api/v1/resultaattypen/111-111-111",
Expand Down
5 changes: 3 additions & 2 deletions backend/src/openarchiefbeheer/zaken/tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,18 @@ def test_filter_heeft_relaties(self):

def test_partial_filter(self):
ZaakFactory.create(identificatie="ZAAK-ABCDEF-01")
ZaakFactory.create(identificatie="ZAAK-ABC-02")
ZaakFactory.create(identificatie="ZAAK-ABC-02", with_expand=True)
ZaakFactory.create(identificatie="ZAAK-BCDEF-02")

user = UserFactory(username="record_manager", role__can_start_destruction=True)

endpoint = furl(reverse("api:zaken-list"))
endpoint.args["identificatie__icontains"] = "ABC"
endpoint.args["zaaktype__omschrijving__icontains"] = "Aangifte behandelen"

self.client.force_authenticate(user)
response = self.client.get(endpoint.url)
data = response.json()

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(data["count"], 2)
self.assertEqual(data["count"], 1)

0 comments on commit ef67588

Please sign in to comment.