Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/256 filter klantcontact on betrokkenen #285

Merged
merged 8 commits into from
Nov 26, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from django.utils.translation import gettext_lazy as _

from django_filters.rest_framework import FilterSet, filters
Expand All @@ -8,7 +6,7 @@
DigitaalAdresSerializer,
)
from openklant.components.klantinteracties.models.digitaal_adres import DigitaalAdres
from openklant.components.utils.filters import ExpandFilter
from openklant.components.utils.filters import ExpandFilter, URLViewFilter


class DigitaalAdresDetailFilterSet(FilterSet):
Expand All @@ -22,11 +20,11 @@ class DigitaalAdresFilterSet(FilterSet):
),
field_name="betrokkene__uuid",
)
verstrekt_door_betrokkene__url = filters.CharFilter(
verstrekt_door_betrokkene__url = URLViewFilter(
help_text=_(
"Zoek digitaal adres(sen) object(en) op basis van de betrokkene url."
),
method="filter_betrokkene_url",
field_name="betrokkene__uuid",
)
verstrekt_door_betrokkene__rol = filters.ChoiceFilter(
help_text=_(
Expand All @@ -36,11 +34,11 @@ class DigitaalAdresFilterSet(FilterSet):
)
verstrekt_door_partij__uuid = filters.UUIDFilter(
help_text=_("Zoek digitaal adres(sen) object(en) op basis van de partij uuid."),
field_name="betrokkene__uuid",
field_name="partij__uuid",
)
verstrekt_door_partij__url = filters.CharFilter(
verstrekt_door_partij__url = URLViewFilter(
help_text=_("Zoek digitaal adres(sen) object(en) op basis van de partij url."),
method="filter_partij_url",
field_name="partij__uuid",
)
verstrekt_door_partij__soort_partij = filters.ChoiceFilter(
help_text=_(
Expand Down Expand Up @@ -90,17 +88,3 @@ class Meta:
"soort_digitaal_adres",
"omschrijving",
)

def filter_betrokkene_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(betrokkene__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(partij__uuid=url_uuid)
except ValueError:
return queryset.none()
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import uuid

from django.utils.translation import gettext_lazy as _

from django_filters.rest_framework import FilterSet, filters

from openklant.components.klantinteracties.models.internetaken import InterneTaak
from openklant.components.utils.filters import URLViewFilter


class InternetaakFilterSet(FilterSet):
toegewezen_aan_actor__uuid = filters.UUIDFilter(
help_text=_("Zoek internetaak object op basis van het toegewezen actor uuid."),
field_name="actoren__uuid",
)
toegewezen_aan_actor__url = filters.CharFilter(
toegewezen_aan_actor__url = URLViewFilter(
help_text=_("Zoek internetaak object op basis van het toegewezen actor url."),
method="filter_toegewezen_aan_actor_url",
field_name="actoren__uuid",
)
aanleidinggevend_klantcontact__uuid = filters.UUIDFilter(
help_text=_(
"Zoek internetaak object op basis van het aanleidingevende klantcontact uuid."
),
field_name="klantcontact__uuid",
)
aanleidinggevend_klantcontact__url = filters.CharFilter(
aanleidinggevend_klantcontact__url = URLViewFilter(
help_text=_(
"Zoek internetaak object op basis van het aanleidingevende klantcontact url."
),
method="filter_aanleidinggevend_klantcontact_url",
field_name="klantcontact__uuid",
)

class Meta:
Expand All @@ -43,17 +42,3 @@ class Meta:
"aanleidinggevend_klantcontact__uuid",
"aanleidinggevend_klantcontact__url",
)

def filter_toegewezen_aan_actor_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(actoren__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_aanleidinggevend_klantcontact_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(klantcontact__uuid=url_uuid)
except ValueError:
return queryset.none()
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import uuid

from django.utils.translation import gettext_lazy as _

from django_filters.rest_framework import FilterSet, filters
Expand All @@ -12,31 +10,39 @@
Betrokkene,
Klantcontact,
)
from openklant.components.utils.filters import ExpandFilter
from openklant.components.utils.filters import ExpandFilter, URLViewFilter


class KlantcontactDetailFilterSet(FilterSet):
expand = ExpandFilter(serializer_class=KlantcontactSerializer)


class KlantcontactFilterSet(FilterSet):
had_betrokkene__url = filters.CharFilter(
had_betrokkene__url = URLViewFilter(
help_text=_("Zoek klantcontact object op basis van het betrokkene url."),
method="filter_betrokkene_url",
field_name="betrokkene__uuid",
)
had_betrokkene__uuid = filters.UUIDFilter(
help_text=_("Zoek klantcontact object op basis van het betrokkene uuid."),
field_name="betrokkene__uuid",
)
onderwerpobject__url = filters.CharFilter(
had_betrokkene__was_partij__url = URLViewFilter(
help_text=_("Zoek klantcontact object op basis van de partij url."),
field_name="betrokkene__partij__uuid",
)
had_betrokkene__was_partij__uuid = filters.UUIDFilter(
help_text=_("Zoek klantcontact object op basis van de partij uuid."),
field_name="betrokkene__partij__uuid",
)
onderwerpobject__url = URLViewFilter(
help_text=_("Zoek klantcontact object op basis van het onderwerpobject url."),
method="filter_onderwerpobject_url",
field_name="onderwerpobject__uuid",
)
was_onderwerpobject__url = filters.CharFilter(
was_onderwerpobject__url = URLViewFilter(
help_text=_(
"Zoek was klantcontact object op basis van het onderwerpobject url."
),
method="filter_was_onderwerpobject_url",
field_name="was_onderwerpobject__uuid",
)
inhoud = filters.CharFilter(
lookup_expr="icontains",
Expand All @@ -54,6 +60,8 @@ class Meta:
fields = (
"had_betrokkene__url",
"had_betrokkene__uuid",
"had_betrokkene__was_partij__url",
"had_betrokkene__was_partij__uuid",
"onderwerpobject__uuid",
"onderwerpobject__url",
"onderwerpobject__onderwerpobjectidentificator_code_objecttype",
Expand All @@ -75,65 +83,44 @@ class Meta:
"plaatsgevonden_op",
)

def filter_betrokkene_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(betrokkene__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_onderwerpobject_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(onderwerpobject__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_was_onderwerpobject_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(was_onderwerpobject__uuid=url_uuid)
except ValueError:
return queryset.none()


class BetrokkeneFilterSet(FilterSet):
had_klantcontact__nummer = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het klantcontact nummer"),
method="filter_had_klantcontact_nummer",
)
had_klantcontact__url = filters.CharFilter(
had_klantcontact__url = URLViewFilter(
help_text=_("Zoek betrokkene object op basis van het klantcontact url"),
method="filter_had_klantcontact_url",
field_name="klantcontact__uuid",
)
had_klantcontact__uuid = filters.CharFilter(
had_klantcontact__uuid = filters.UUIDFilter(
help_text=_("Zoek betrokkene object op basis van het klantcontact uuid"),
method="filter_had_klantcontact_uuid",
field_name="klantcontact__uuid",
)
verstrektedigitaal_adres__adres = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het digitaaladres adres"),
method="filter_digitaaladres_adres",
)
verstrektedigitaal_adres__url = filters.CharFilter(
verstrektedigitaal_adres__url = URLViewFilter(
help_text=_("Zoek betrokkene object op basis van het digitaaladres url"),
method="filter_digitaaladres_url",
field_name="digitaaladres__uuid",
)
verstrektedigitaal_adres__uuid = filters.CharFilter(
verstrektedigitaal_adres__uuid = filters.UUIDFilter(
help_text=_("Zoek betrokkene object op basis van het digitaaladres uuid"),
method="filter_digitaaladres_uuid",
field_name="digitaaladres__uuid",
)

was_partij__nummer = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het partij nummer"),
method="filter_partij_nummer",
)
was_partij__url = filters.CharFilter(
was_partij__url = URLViewFilter(
help_text=_("Zoek betrokkene object op basis van het partij url"),
method="filter_partij_url",
field_name="partij__uuid",
)
was_partij__uuid = filters.CharFilter(
was_partij__uuid = filters.UUIDFilter(
help_text=_("Zoek betrokkene object op basis van het partij uuid"),
method="filter_partij_uuid",
field_name="partij__uuid",
)

class Meta:
Expand All @@ -155,20 +142,6 @@ class Meta:
"organisatienaam",
)

def filter_had_klantcontact_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(klantcontact__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_had_klantcontact_uuid(self, queryset, name, value):
try:
klantcontact_uuid = uuid.UUID(value)
return queryset.filter(klantcontact__uuid=klantcontact_uuid)
except ValueError:
return queryset.none()

def filter_had_klantcontact_nummer(self, queryset, name, value):
try:
return queryset.filter(klantcontact__nummer=value)
Expand All @@ -178,48 +151,20 @@ def filter_had_klantcontact_nummer(self, queryset, name, value):
def filter_digitaaladres_adres(self, queryset, name, value):
return queryset.filter(digitaaladres__adres=value)

def filter_digitaaladres_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(digitaaladres__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_digitaaladres_uuid(self, queryset, name, value):
try:
digitaaladres_uuid = uuid.UUID(value)
return queryset.filter(digitaaladres__uuid=digitaaladres_uuid)
except ValueError:
return queryset.none()

def filter_partij_nummer(self, queryset, name, value):
return queryset.filter(partij__nummer=value)

def filter_partij_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(partij__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_partij_uuid(self, queryset, name, value):
try:
partij_uuid = uuid.UUID(value)
return queryset.filter(partij__uuid=partij_uuid)
except ValueError:
return queryset.none()


class ActorKlantcontactFilterSet(FilterSet):
actor__url = filters.CharFilter(
actor__url = URLViewFilter(
help_text=_("Zoek actor klantcontract object op basis van het actor url"),
method="filter_actor_url",
field_name="actor__uuid",
)
klantcontact__url = filters.CharFilter(
klantcontact__url = URLViewFilter(
help_text=_(
"Zoek actor klantcontract object op basis van het klantcontact url"
),
method="filter_klantcontact_url",
field_name="klantcontact__uuid",
)

class Meta:
Expand All @@ -230,17 +175,3 @@ class Meta:
"klantcontact__uuid",
"klantcontact__url",
)

def filter_actor_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(actor__uuid=url_uuid)
except ValueError:
return queryset.none()

def filter_klantcontact_url(self, queryset, name, value):
try:
url_uuid = uuid.UUID(value.rstrip("/").split("/")[-1])
return queryset.filter(klantcontact__uuid=url_uuid)
except ValueError:
return queryset.none()
Loading
Loading