-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 changes to add separate adres for betrokkene
- Loading branch information
Showing
17 changed files
with
628 additions
and
61 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/openklant/components/klantinteracties/admin/betrokkene_adres.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.contrib import admin | ||
|
||
from ..models.digitaal_adres import BetrokkeneAdres | ||
from .digitaal_adres import BaseAdresAdminForm | ||
|
||
|
||
class BetrokkeneAdresAdminForm(BaseAdresAdminForm): | ||
class Meta: | ||
model = BetrokkeneAdres | ||
fields = "__all__" | ||
|
||
|
||
@admin.register(BetrokkeneAdres) | ||
class BetrokkeneAdresAdmin(admin.ModelAdmin): | ||
readonly_fields = ("uuid",) | ||
search_fields = ("adres",) | ||
autocomplete_fields = ("betrokkene",) | ||
form = BetrokkeneAdresAdminForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/openklant/components/klantinteracties/api/serializers/betrokkene_adres.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from django.db import transaction | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from rest_framework import serializers | ||
|
||
from openklant.components.klantinteracties.api.serializers.constants import ( | ||
SERIALIZER_PATH, | ||
) | ||
from openklant.components.klantinteracties.api.validators import ( | ||
OptionalEmailValidator, | ||
betrokkene_adres_exists, | ||
) | ||
from openklant.components.klantinteracties.models.digitaal_adres import BetrokkeneAdres | ||
from openklant.components.klantinteracties.models.klantcontacten import Betrokkene | ||
from openklant.utils.serializers import get_field_value | ||
|
||
|
||
class BetrokkeneAdresForeignKeySerializer(serializers.HyperlinkedModelSerializer): | ||
class Meta: | ||
model = BetrokkeneAdres | ||
fields = ( | ||
"uuid", | ||
"url", | ||
) | ||
extra_kwargs = { | ||
"uuid": {"required": True, "validators": [betrokkene_adres_exists]}, | ||
"url": { | ||
"view_name": "klantinteracties:betrokkeneadres-detail", | ||
"lookup_field": "uuid", | ||
"help_text": _( | ||
"De unieke URL van dit betrokkene adres binnen deze API." | ||
), | ||
}, | ||
} | ||
|
||
|
||
class BetrokkeneAdresSerializer(serializers.HyperlinkedModelSerializer): | ||
from openklant.components.klantinteracties.api.serializers.klantcontacten import ( | ||
BetrokkeneForeignKeySerializer, | ||
) | ||
|
||
verstrekt_door_betrokkene = BetrokkeneForeignKeySerializer( | ||
required=True, | ||
allow_null=True, | ||
help_text=_( | ||
"Digitaal adres dat een betrokkene bij klantcontact verstrekte voor gebruik bij " | ||
"opvolging van een klantcontact." | ||
), | ||
source="betrokkene", | ||
) | ||
|
||
inclusion_serializers = { | ||
# 1 level | ||
"verstrekt_door_betrokkene": f"{SERIALIZER_PATH}.klantcontacten.BetrokkeneSerializer", | ||
# 2 levels | ||
"verstrekt_door_betrokkene.had_klantcontact": f"{SERIALIZER_PATH}.klantcontacten.KlantcontactSerializer", | ||
# 3 levels | ||
"verstrekt_door_betrokkene.had_klantcontact.leidde_tot_interne_taken": f"{SERIALIZER_PATH}" | ||
".internetaken.InterneTaakSerializer", | ||
} | ||
|
||
class Meta: | ||
model = BetrokkeneAdres | ||
fields = ( | ||
"uuid", | ||
"url", | ||
"verstrekt_door_betrokkene", | ||
"adres", | ||
"soort_digitaal_adres", | ||
"omschrijving", | ||
) | ||
extra_kwargs = { | ||
"uuid": {"read_only": True}, | ||
"url": { | ||
"view_name": "klantinteracties:betrokkeneadres-detail", | ||
"lookup_field": "uuid", | ||
"help_text": _( | ||
"De unieke URL van dit betrokkene adres binnen deze API." | ||
), | ||
}, | ||
} | ||
|
||
def validate_adres(self, adres): | ||
""" | ||
Define the validator here, to avoid DRF spectacular marking the format for | ||
`adres` as `email` | ||
""" | ||
soort_digitaal_adres = get_field_value( | ||
self, self.initial_data, "soort_digitaal_adres" | ||
) | ||
OptionalEmailValidator()(adres, soort_digitaal_adres) | ||
return adres | ||
|
||
@transaction.atomic | ||
def update(self, instance, validated_data): | ||
if "betrokkene" in validated_data: | ||
if betrokkene := validated_data.pop("betrokkene", None): | ||
betrokkene = Betrokkene.objects.get(uuid=str(betrokkene.get("uuid"))) | ||
|
||
validated_data["betrokkene"] = betrokkene | ||
|
||
return super().update(instance, validated_data) | ||
|
||
@transaction.atomic | ||
def create(self, validated_data): | ||
if betrokkene := validated_data.pop("betrokkene", None): | ||
validated_data["betrokkene"] = Betrokkene.objects.get( | ||
uuid=str(betrokkene.get("uuid")) | ||
) | ||
|
||
return super().create(validated_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,7 +183,7 @@ def test_create_digitaal_adres_is_standaard_adres(self): | |
"verstrektDoorBetrokkene": None, | ||
"verstrektDoorPartij": {"uuid": str(partij2.uuid)}, | ||
"soortDigitaalAdres": "email", | ||
"adres": "adres", | ||
"adres": "[email protected]", | ||
"omschrijving": "omschrijving", | ||
"isStandaardAdres": True, | ||
} | ||
|
@@ -300,7 +300,7 @@ def test_update_digitaal_adres_is_standaard_adres(self): | |
"verstrektDoorPartij": {"uuid": str(partij2.uuid)}, | ||
"soortDigitaalAdres": "email", | ||
"isStandaardAdres": True, | ||
"adres": "changed", | ||
"adres": "[email protected]", | ||
"omschrijving": "changed", | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.