Skip to content

Commit

Permalink
[#2899] Create MVP configuration model for OpenKlant2
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schilling committed Jan 7, 2025
1 parent 235d0f0 commit 33b0d88
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 49 deletions.
55 changes: 54 additions & 1 deletion src/open_inwoner/openklant/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
from ordered_model.admin import OrderedInlineModelAdminMixin, OrderedTabularInline
from solo.admin import SingletonModelAdmin

from .models import ContactFormSubject, KlantContactMomentAnswer, OpenKlantConfig
from .models import (
ContactFormSubject,
KlantContactMomentAnswer,
KlantenInteractiesConfig,
OpenKlant2Config,
OpenKlantConfig,
)


class ContactFormSubjectForm(forms.ModelForm):
Expand Down Expand Up @@ -108,3 +114,50 @@ class KlantContactMomentAnswerAdmin(admin.ModelAdmin):
]
list_filter = ["is_seen"]
list_display = ["user", "contactmoment_url", "is_seen"]


#
# OpenKlant2
#


class OpenKlant2ConfigAdminForm(forms.ModelForm):
class Meta:
model = OpenKlantConfig
fields = "__all__"


@admin.register(OpenKlant2Config)
class OpenKlant2Config2Admin(admin.ModelAdmin):
model = OpenKlant2Config
form = OpenKlant2ConfigAdminForm
fieldsets = [
(
_("API configuration"),
{
"fields": [
"service",
]
},
),
(
_("Vragen"),
{
"fields": [
"mijn_vragen_kanaal",
"mijn_vragen_organisatie_naam",
"mijn_vragen_actor",
"interne_taak_gevraagde_handeling",
"interne_taak_toelichting",
]
},
),
]


@admin.register(KlantenInteractiesConfig)
class KlantenInteractiesConfigAdmin(SingletonModelAdmin):
change_form_template = "admin/openklant/klanteninteractiesconfig/change_form.html"

class Meta:
model = KlantenInteractiesConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.16 on 2025-01-07 11:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openklant", "0015_openklant2config"),
]

operations = [
migrations.CreateModel(
name="KlantenInteractiesConfig",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"primary_backend",
models.CharField(
choices=[("esuite", "ESUITE"), ("openklant2", "OPENKLANT2")],
max_length=10,
help_text="Choose the primary backend for retrieving klanten data. Changes to klanten data will be saved to both backends (if configured).",
),
),
],
options={
"verbose_name": "Configuratie Klanten Interacties",
},
),
]
111 changes: 63 additions & 48 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from open_inwoner.utils.validators import validate_array_contents_non_empty

from .constants import KlantenServiceType


class OpenKlantConfigManager(models.Manager):
def get_queryset(self):
Expand All @@ -17,7 +19,7 @@ def get_queryset(self):

class OpenKlantConfig(SingletonModel):
"""
Global configuration and defaults for Klant & Contactmomenten APIs
Configuration and defaults for eSuite Klant & Contactmomenten APIs
"""

klanten_service = models.OneToOneField(
Expand Down Expand Up @@ -132,51 +134,6 @@ def has_api_configuration(self):
return all(getattr(self, f, "") for f in self.register_api_required_fields)


class OpenKlant2ConfigManager(models.Manager):
def get_queryset(self):
qs = super().get_queryset()
return qs.select_related("service")


class OpenKlant2Config(models.Model):
service = models.OneToOneField(
"zgw_consumers.Service",
verbose_name=_("Klanten API"),
on_delete=models.PROTECT,
related_name="+",
)

# Vragen
mijn_vragen_kanaal = models.CharField(
verbose_name=_("Mijn vragen kanaal"),
default="",
blank=True,
)
mijn_vragen_organisatie_naam = models.CharField(
verbose_name=_("Mijn vragen organisatie naam"),
default="",
blank=True,
)
mijn_vragen_actor = models.CharField(
verbose_name=_("Mijn vragen actor"),
default="",
blank=True,
)
interne_taak_gevraagde_handeling = models.CharField(
verbose_name=_("Interne taak gevraagde handeling"),
default="",
blank=True,
)
interne_taak_toelichting = models.CharField(
verbose_name=_("Interne taak toelichting"),
default="",
blank=True,
)

class Meta:
verbose_name = _("OpenKlant2 configuration")


class ContactFormSubject(OrderedModel):
subject = models.CharField(
verbose_name=_("Onderwerp"),
Expand All @@ -187,9 +144,8 @@ class ContactFormSubject(OrderedModel):
max_length=255,
blank=True,
)
# FK for easy inline admins
config = models.ForeignKey(
OpenKlantConfig,
"OpenKlantConfig",
on_delete=models.CASCADE,
)

Expand Down Expand Up @@ -229,3 +185,62 @@ class Meta:
verbose_name = _("KlantContactMoment")
verbose_name_plural = _("KlantContactMomenten")
unique_together = [["user", "contactmoment_url"]]


class OpenKlant2ConfigManager(models.Manager):
def get_queryset(self):
qs = super().get_queryset()
return qs.select_related("service")


class OpenKlant2Config(models.Model):
service = models.OneToOneField(
"zgw_consumers.Service",
verbose_name=_("Klanten API"),
on_delete=models.PROTECT,
related_name="+",
)

# Vragen
mijn_vragen_kanaal = models.CharField(
verbose_name=_("Mijn vragen kanaal"),
default="",
blank=True,
)
mijn_vragen_organisatie_naam = models.CharField(
verbose_name=_("Mijn vragen organisatie naam"),
default="",
blank=True,
)
mijn_vragen_actor = models.CharField(
verbose_name=_("Mijn vragen actor"),
default="",
blank=True,
)
interne_taak_gevraagde_handeling = models.CharField(
verbose_name=_("Interne taak gevraagde handeling"),
default="",
blank=True,
)
interne_taak_toelichting = models.CharField(
verbose_name=_("Interne taak toelichting"),
default="",
blank=True,
)

class Meta:
verbose_name = _("OpenKlant2 configuration")


class KlantenInteractiesConfig(SingletonModel):
primary_backend = models.CharField(
max_length=10,
choices=[(service.value, service.name) for service in KlantenServiceType],
help_text=_(
"Choose the primary backend for retrieving klanten data. "
"Changes to klanten data will be saved to both backends (if configured)."
),
)

class Meta:
verbose_name = _("Configuratie Klanten Interacties")
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "admin/solo/change_form.html" %}

{% block content %}
<p>Configure the backends for retrieving Klanten data:</p>
<ul>
<li><a href="{% url 'admin:openklant_openklantconfig_change' %}">Configure eSuite backend</a></li>
<li><a href="{% url 'admin:openklant_openklant2config_change' 1 %}">Configure OpenKlant2 backend</a></li>
</ul>
{{ block.super }}
{% endblock content %}

0 comments on commit 33b0d88

Please sign in to comment.