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

[#2899] Create MVP configuration model for OpenKlant2 #1520

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 60 additions & 3 deletions 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,
OpenKlant2Config2,
OpenKlantConfig,
)


class ContactFormSubjectForm(forms.ModelForm):
Expand Down Expand Up @@ -49,8 +55,8 @@ def clean(self, *args, **kwargs):
self.add_error(field_name, msg)


@admin.register(OpenKlantConfig)
class OpenKlantConfigAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
class OpenKlantConfigAdmin(admin.StackedInline):
model = OpenKlantConfig
form = OpenKlantConfigAdminForm
inlines = [
ContactFormSubjectInlineAdmin,
Expand Down Expand Up @@ -108,3 +114,54 @@ 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__"


class OpenKlant2Config2Admin(admin.StackedInline):
model = OpenKlant2Config2
form = OpenKlant2ConfigAdminForm
fieldsets = [
(
_("API configuration"),
{
"fields": [
"api_root",
"api_token",
]
},
),
(
_("Vragen"),
{
"fields": [
"mijn_vragen_kanaal",
"mijn_vragen_organisatie_naam",
"mijn_vragen_actor",
"interne_taak_gevraagde_handeling",
"interne_taak_toelichting",
]
},
),
]

class Media:
css = {"all": ("css/custom_admin.css",)}


@admin.register(KlantenInteractiesConfig)
class KlantenInteractiesConfigAdmin(OrderedInlineModelAdminMixin, SingletonModelAdmin):
inlines = [
OpenKlant2Config2Admin,
OpenKlantConfigAdmin,
ContactFormSubjectInlineAdmin,
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Generated by Django 4.2.16 on 2024-12-05 11:49

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openklant", "0014_contactformconfig"),
]

operations = [
migrations.CreateModel(
name="KlantenInteractiesConfig",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
],
options={
"verbose_name": "Configuratie Klanten Interacties",
},
),
migrations.AlterModelOptions(
name="openklantconfig",
options={"verbose_name": "Esuite configuration"},
),
migrations.CreateModel(
name="OpenKlant2Config2",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("api_root", models.URLField(verbose_name="API root url")),
("api_token", models.CharField(verbose_name="API key token")),
(
"mijn_vragen_kanaal",
models.CharField(verbose_name="Mijn vragen kanaal"),
),
(
"mijn_vragen_organisatie_naam",
models.CharField(verbose_name="Mijn vragen organisatie naam"),
),
(
"mijn_vragen_actor",
models.CharField(verbose_name="Mijn vragen actor"),
),
(
"interne_taak_gevraagde_handeling",
models.CharField(verbose_name="Interne taak gevraagde handeling"),
),
(
"interne_taak_toelichting",
models.CharField(verbose_name="Interne taak toelichting"),
),
(
"config",
models.OneToOneField(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="openklant.klanteninteractiesconfig",
),
),
],
options={
"verbose_name": "Open Klant configuration",
},
),
migrations.AddField(
model_name="openklantconfig",
name="config",
field=models.OneToOneField(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="openklant.klanteninteractiesconfig",
),
),
migrations.AlterField(
model_name="contactformsubject",
name="config",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="openklant.klanteninteractiesconfig",
),
),
]
54 changes: 51 additions & 3 deletions src/open_inwoner/openklant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ class OpenKlantConfig(SingletonModel):
validators=[validate_array_contents_non_empty],
)

# FK for easy inline admins
config = models.OneToOneField(
"KlantenInteractiesConfig",
null=True,
on_delete=models.CASCADE,
)

register_api_required_fields = (
"register_contact_moment",
"contactmomenten_service",
Expand All @@ -126,7 +133,7 @@ class OpenKlantConfig(SingletonModel):
objects = OpenKlantConfigManager()

class Meta:
verbose_name = _("Open Klant configuration")
verbose_name = _("Esuite configuration")

def has_register(self) -> bool:
return self.register_email or self.has_api_configuration()
Expand All @@ -150,7 +157,7 @@ class ContactFormSubject(OrderedModel):
)
# FK for easy inline admins
config = models.ForeignKey(
OpenKlantConfig,
"KlantenInteractiesConfig",
on_delete=models.CASCADE,
)

Expand Down Expand Up @@ -223,4 +230,45 @@ def from_django_settings(cls) -> Self:

return cls(**config)

# TODO: add from_openklant_config_model or similar

# TODO: rename after removing dataclass config
class OpenKlant2Config2(SingletonModel):
api_root = models.URLField(
verbose_name=_("API root url"),
)
api_token = models.CharField(
verbose_name=_("API key token"),
)

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

# FK for admin inline
config = models.OneToOneField(
"KlantenInteractiesConfig",
null=True,
blank=True,
on_delete=models.CASCADE,
)

class Meta:
verbose_name = _("Open Klant configuration")


class KlantenInteractiesConfig(SingletonModel):
class Meta:
verbose_name = _("Configuratie Klanten Interacties")
17 changes: 17 additions & 0 deletions src/open_inwoner/scss/admin/_admin_inlines.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.inline-group {
margin-bottom: 16px;

border: 1px solid #ddd;
border-radius: 5px;

> fieldset > h2 {
margin-bottom: 5px;
background-color: #498fc9;
}
}

.inline-related {
h3 {
display: none;
}
}
1 change: 1 addition & 0 deletions src/open_inwoner/scss/admin/admin_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//Internal
@import './admin_theme';
@import './admin_inlines';
@import './app_overrides';
@import './ck_editor';
@import '../components/Map/Map.scss';
Loading