Skip to content

Commit

Permalink
✨ [#100] added klantinteracties api, updated models and updated admin
Browse files Browse the repository at this point in the history
  • Loading branch information
bart-maykin committed Nov 24, 2023
1 parent e3c5fb6 commit f0c0533
Show file tree
Hide file tree
Showing 48 changed files with 23,097 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
@admin.register(DigitaalAdres)
class DigitaalAdresAdmin(admin.ModelAdmin):
search_fields = ("adres",)
autocomplete_fields = ("partij",)
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class BetrokkeneInlineAdmin(admin.StackedInline):
"contactnaam_voorvoegsel_achternaam",
"contactnaam_achternaam",
)
autocomplete_fields = ("partij",)
fieldsets = [
(
None,
{
"fields": [
"partij",
"klantcontact",
"digitaal_adres",
"rol",
"organisatienaam",
"initiator",
Expand Down Expand Up @@ -71,14 +72,14 @@ class BetrokkeneAdmin(admin.ModelAdmin):
"contactnaam_voorvoegsel_achternaam",
"contactnaam_achternaam",
)
raw_id_fields = ["digitaal_adres"]
autocomplete_fields = ("partij",)
fieldsets = [
(
None,
{
"fields": [
"partij",
"klantcontact",
"digitaal_adres",
"rol",
"organisatienaam",
"initiator",
Expand Down
36 changes: 29 additions & 7 deletions src/openklant/components/klantinteracties/admin/partijen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
from django.utils.translation import gettext_lazy as _

from ..models.constants import SoortPartij
from ..models.digitaal_adres import DigitaalAdres
from ..models.klantcontacten import Betrokkene
from ..models.partijen import Contactpersoon, Organisatie, Partij, Persoon


class DigitaalAdresInlineAdmin(admin.StackedInline):
model = DigitaalAdres
extra = 0


class BetrokkeneInlineAdmin(admin.StackedInline):
model = Betrokkene
extra = 0


class PersoonInlineAdmin(admin.StackedInline):
model = Persoon
extra = 0
Expand Down Expand Up @@ -32,19 +44,20 @@ class PartijAdmin(admin.ModelAdmin):
"soort_partij",
"indicatie_actief",
)
inlines = (PersoonInlineAdmin, ContactpersoonInlineAdmin, OrganisatieInlineAdmin)
autocomplete_fields = (
"betrokkene",
"digitaal_adres",
"voorkeurs_digitaal_adres",
inlines = (
PersoonInlineAdmin,
ContactpersoonInlineAdmin,
OrganisatieInlineAdmin,
DigitaalAdresInlineAdmin,
BetrokkeneInlineAdmin,
)
search_fields = ("partij",)
autocomplete_fields = ("voorkeurs_digitaal_adres",)
fieldsets = [
(
None,
{
"fields": [
"betrokkene",
"digitaal_adres",
"voorkeurs_digitaal_adres",
"vertegenwoordigde",
"nummer",
Expand Down Expand Up @@ -82,6 +95,15 @@ class PartijAdmin(admin.ModelAdmin):
),
]

def get_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related(
"voorkeurs_digitaal_adres",
)
)

@admin.display(empty_value="---")
def get_name(self, obj):
match obj.soort_partij:
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions src/openklant/components/klantinteracties/api/filterset/actoren.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.utils.translation import gettext_lazy as _

from django_filters.rest_framework import FilterSet, filters

from openklant.components.klantinteracties.models.actoren import Actor


class ActorenFilterSet(FilterSet):
naam = filters.CharFilter(
lookup_expr="icontains",
help_text=_("Zoek klantcontacten met specifieke tekst in inhoud"),
)

class Meta:
model = Actor
fields = (
"naam",
"soort_actor",
"indicatie_actief",
"objectidentificator_objecttype",
"objectidentificator_soort_object_id",
"objectidentificator_object_id",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import uuid

from django.utils.translation import gettext_lazy as _

from django_filters.rest_framework import FilterSet, filters

from openklant.components.klantinteracties.models.klantcontacten import (
Betrokkene,
Klantcontact,
)


class KlantcontactFilterSet(FilterSet):
had_betrokkene__url = filters.CharFilter(
help_text=_("Zoek klantcontract object op basis van het betrokkene url"),
method="filter_betrokkene_url",
)
had_betrokkene__uuid = filters.CharFilter(
help_text=_("Zoek klantcontract object op basis van het betrokkene uuid"),
method="filter_betrokkene_uuid",
)
inhoud = filters.CharFilter(
lookup_expr="icontains",
help_text=_("Zoek klantcontacten met specifieke tekst in inhoud"),
)
onderwerp = filters.CharFilter(
lookup_expr="icontains",
help_text=_("Zoek klantcontacten met specifieke tekst in onderwerp"),
)

class Meta:
model = Klantcontact
fields = (
"had_betrokkene__url",
"had_betrokkene__uuid",
"nummer",
"kanaal",
"inhoud",
"onderwerp",
)

def filter_betrokkene_uuid(self, queryset, name, value):
try:
betrokkene_uuid = uuid.UUID(value)
return queryset.filter(betrokkene__uuid=betrokkene_uuid)
except ValueError:
return queryset.none()

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


class BetrokkeneFilterSet(FilterSet):
klantcontact__nummer = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het klantcontact nummer"),
method="filter_klantcontact_nummer",
)
klantcontact__url = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het klantcontact url"),
method="filter_klantcontact_url",
)
klantcontact__uuid = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het klantcontact uuid"),
method="filter_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(
help_text=_("Zoek betrokkene object op basis van het digitaaladres url"),
method="filter_digitaaladres_url",
)
verstrektedigitaal_adres__uuid = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het digitaaladres uuid"),
method="filter_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(
help_text=_("Zoek betrokkene object op basis van het partij url"),
method="filter_partij_url",
)
was_partij__uuid = filters.CharFilter(
help_text=_("Zoek betrokkene object op basis van het partij uuid"),
method="filter_partij_uuid",
)

class Meta:
model = Betrokkene
fields = (
"klantcontact__nummer",
"klantcontact__uuid",
"klantcontact__url",
"verstrektedigitaal_adres__adres",
"verstrektedigitaal_adres__uuid",
"verstrektedigitaal_adres__url",
"was_partij__nummer",
"was_partij__url",
"was_partij__uuid",
)

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

def filter_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_klantcontact_nummer(self, queryset, name, value):
try:
return queryset.filter(klantcontact__nummer=value)
except ValueError:
return queryset.none()

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.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.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()
Loading

0 comments on commit f0c0533

Please sign in to comment.