Skip to content

Commit c5de28e

Browse files
committed
[#2856] Make contact form plugin configurable via CMS
1 parent 3192304 commit c5de28e

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

src/open_inwoner/conf/base.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@
580580
"ProductLocationPlugin",
581581
"UserFeedPlugin",
582582
"UserAppointmentsPlugin",
583+
"ContactFormPlugin",
583584
],
584585
"text_only_plugins": ["LinkPlugin"],
585586
"name": _("Content"),
@@ -615,10 +616,6 @@
615616
"TextPlugin": ["LinkPlugin"],
616617
},
617618
},
618-
"contact_form": {
619-
"name": _("Contact form plugin"),
620-
"plugins": ["ContactFormPlugin"],
621-
},
622619
}
623620

624621
CMS_TOOLBAR_ANONYMOUS_ON = False

src/open_inwoner/openklant/cms_plugins.py

+31
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
from cms.plugin_pool import plugin_pool
88

99
from open_inwoner.ckeditor5.widgets import CKEditorWidget
10+
from open_inwoner.openklant.forms import ContactForm
11+
from open_inwoner.openklant.models import OpenKlantConfig
1012

1113
#
1214
# contact form plugin
1315
#
1416

1517

1618
class ContactFormConfig(CMSPlugin):
19+
title = models.TextField(
20+
_("Title"),
21+
blank=True,
22+
help_text=_("Title of the contact form."),
23+
)
1724
description = models.TextField(
1825
_("Description"),
1926
blank=True,
@@ -26,6 +33,7 @@ class Meta:
2633
model = ContactFormConfig
2734
fields = "__all__"
2835
widgets = {
36+
"title": CKEditorWidget,
2937
"description": CKEditorWidget,
3038
}
3139

@@ -37,3 +45,26 @@ class ContactFormPlugin(CMSPluginBase):
3745
name = _("Contact form plugin")
3846
render_template = "pages/contactform/form.html"
3947
cache = False
48+
49+
fieldsets = ((None, {"fields": ("title", "description")}),)
50+
51+
# def get_render_template(self, context, instance, placeholder):
52+
# request = context["request"]
53+
# if request.path == "/contactform/":
54+
# return "pages/contactform/form.html"
55+
# return ""
56+
57+
def render(self, context, instance, placeholder):
58+
config = OpenKlantConfig.get_solo()
59+
context.update(
60+
{
61+
"has_form_configuration": config.has_form_configuration(),
62+
"form": ContactForm(
63+
user=context["user"], request_session=context["request"].session
64+
),
65+
"instance": instance,
66+
"title": instance.title,
67+
"description": instance.description,
68+
}
69+
)
70+
return context
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 4.2.16 on 2024-11-27 15:23
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("openklant", "0014_contactformconfig"),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name="contactformconfig",
15+
name="title",
16+
field=models.TextField(
17+
blank=True, help_text="Title of the contact form.", verbose_name="Title"
18+
),
19+
),
20+
]
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{% load cms_tags i18n render_tags %}
22

3-
{% block content %}
43
{% if has_form_configuration %}
54
<h1 class="utrecht-heading-1">
65
{% trans "Contactformulier" %}
@@ -10,4 +9,3 @@ <h1 class="utrecht-heading-1">
109
{% else %}
1110
<p class="utrecht-paragraph">{% trans "Contact formulier niet geconfigureerd." %}</p>
1211
{% endif %}
13-
{% endblock content %}

src/open_inwoner/urls.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
ResendTokenView,
2929
VerifyTokenView,
3030
)
31-
from open_inwoner.openklant.views.contactform import ContactFormView
31+
32+
# TODO: remove
33+
# from open_inwoner.openklant.views.contactform import ContactFormView
3234
from open_inwoner.pdc.views import FAQView
3335

3436
handler500 = "open_inwoner.utils.views.server_error"
@@ -112,7 +114,8 @@
112114
"sessions/",
113115
include("open_inwoner.extended_sessions.urls", namespace="sessions"),
114116
),
115-
path("contactformulier/", ContactFormView.as_view(), name="contactform"),
117+
# TODO: remove
118+
# path("contactformulier/", ContactFormView.as_view(), name="contactform"),
116119
path("oidc/", include("mozilla_django_oidc.urls")),
117120
path("digid-oidc/", include("open_inwoner.accounts.digid_urls")),
118121
path("eherkenning-oidc/", include("open_inwoner.accounts.eherkenning_urls")),

0 commit comments

Comments
 (0)