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

[#2856] Make contact form plugin configurable via CMS #1504

Draft
wants to merge 2 commits 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
6 changes: 2 additions & 4 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@

CMS_TEMPLATES = [
("cms/fullwidth.html", "Home page template"),
("cms/basic.html", "Base template for CMS pages"),
]
CMS_PLACEHOLDER_CONF = {
# TODO properly configure this based on actual available plugins
Expand All @@ -580,6 +581,7 @@
"ProductLocationPlugin",
"UserFeedPlugin",
"UserAppointmentsPlugin",
"ContactFormPlugin",
],
"text_only_plugins": ["LinkPlugin"],
"name": _("Content"),
Expand Down Expand Up @@ -615,10 +617,6 @@
"TextPlugin": ["LinkPlugin"],
},
},
"contact_form": {
"name": _("Contact form plugin"),
"plugins": ["ContactFormPlugin"],
},
}

CMS_TOOLBAR_ANONYMOUS_ON = False
Expand Down
26 changes: 26 additions & 0 deletions src/open_inwoner/openklant/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
from cms.plugin_pool import plugin_pool

from open_inwoner.ckeditor5.widgets import CKEditorWidget
from open_inwoner.openklant.forms import ContactForm
from open_inwoner.openklant.models import OpenKlantConfig

#
# contact form plugin
#


class ContactFormConfig(CMSPlugin):
title = models.TextField(
_("Title"),
blank=True,
help_text=_("Title of the contact form."),
)
description = models.TextField(
_("Description"),
blank=True,
Expand All @@ -26,6 +33,7 @@ class Meta:
model = ContactFormConfig
fields = "__all__"
widgets = {
"title": CKEditorWidget,
"description": CKEditorWidget,
}

Expand All @@ -36,4 +44,22 @@ class ContactFormPlugin(CMSPluginBase):
form = ContactFormConfigForm
name = _("Contact form plugin")
render_template = "pages/contactform/form.html"
# render_template = "cms/contactform/form.html"
cache = False

fieldsets = ((None, {"fields": ("title", "description")}),)

def render(self, context, instance, placeholder):
config = OpenKlantConfig.get_solo()
context.update(
{
"has_form_configuration": config.has_form_configuration(),
"form": ContactForm(
user=context["user"], request_session=context["request"].session
),
"instance": instance,
"title": instance.title,
"description": instance.description,
}
)
return context
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.16 on 2024-11-27 15:23

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.AddField(
model_name="contactformconfig",
name="title",
field=models.TextField(
blank=True, help_text="Title of the contact form.", verbose_name="Title"
),
),
]
14 changes: 14 additions & 0 deletions src/open_inwoner/templates/cms/basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends 'master.html' %}
{% load i18n cms_tags sekizai_tags static %}


{% block extra_head %}
{% page_attribute "meta_description" as meta_description %}
{{ block.super }}
<meta name="description" content="{{ meta_description }}" />
{% endblock extra_head %}

{% block title %}{% page_attribute "title" as title %}{% page_attribute "page_title" as page_title %}{% if page_title %}{{ page_title }}{% else %}{{ title }}{% endif %} - {{ site_name }}{% endblock title %}
{% block content %}
{% placeholder 'content' or %}{% trans "There is no content." %}{% endplaceholder %}
{% endblock content %}
13 changes: 13 additions & 0 deletions src/open_inwoner/templates/cms/contactform/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load cms_tags i18n render_tags %}

{% block content %}
{% if has_form_configuration %}
<h1 class="utrecht-heading-1">
{% trans "Contactformulier" %}
</h1>
<p class="utrecht-paragraph">{{ instance.description|ckeditor_content|safe }}</p>
{% include "components/Contact/ContactForm.html" with form_object=form has_form_configuration=has_form_configuration csrf_token=csrf_token only %}
{% else %}
<p class="utrecht-paragraph">{% trans "Contact formulier niet geconfigureerd." %}</p>
{% endif %}
{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ul class="footer__list">
{% if has_form_configuration %}
<li class="footer__list-item">
{% link text=_("Contact formulier") secondary=True href="contactform" %}
{% link text=_("Contact formulier") secondary=True href="contactforms" %}
</li>
{% endif %}
{% for flatpage in flatpages %}
Expand Down
1 change: 0 additions & 1 deletion src/open_inwoner/templates/cms/fullwidth.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

{% block title %}{% page_attribute "title" as title %}{% page_attribute "page_title" as page_title %}{% if page_title %}{{ page_title }}{% else %}{{ title }}{% endif %} - {{ site_name }}{% endblock title %}


{% block header_image %}
{% if request.user.is_authenticated %}
{% placeholder 'banner_image' %}
Expand Down
4 changes: 2 additions & 2 deletions src/open_inwoner/templates/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</head>

<body hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' class="utrecht-page">

{% if cookiebanner_enabled %}
{# render cookiebanner first #}
<div class="cookie-banner" id="cookie-banner" aria-labelledby="cookie-banner__title" aria-describedby="cookie-banner__text">
Expand All @@ -79,7 +79,7 @@
</div>
</div>
{% endif %}

{% include "components/Header/AccessibilitySkipLink.html" %}

{% if warning_banner_enabled %}
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/templates/pages/contactform/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}
{% if has_form_configuration %}
<h1 class="utrecht-heading-1">
{% trans "Contactformulier" %}
{% if instance.title %}{{ instance.title }}{% else %}{% trans "Contactformulier" %}{% endif %}
</h1>
<p class="utrecht-paragraph">{{ instance.description|ckeditor_content|safe }}</p>
{% include "components/Contact/ContactForm.html" with form_object=form has_form_configuration=has_form_configuration csrf_token=csrf_token only %}
Expand Down
7 changes: 5 additions & 2 deletions src/open_inwoner/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
ResendTokenView,
VerifyTokenView,
)
from open_inwoner.openklant.views.contactform import ContactFormView

# TODO: remove
# from open_inwoner.openklant.views.contactform import ContactFormView
from open_inwoner.pdc.views import FAQView

handler500 = "open_inwoner.utils.views.server_error"
Expand Down Expand Up @@ -112,7 +114,8 @@
"sessions/",
include("open_inwoner.extended_sessions.urls", namespace="sessions"),
),
path("contactformulier/", ContactFormView.as_view(), name="contactform"),
# TODO: remove
# path("contactformulier/", ContactFormView.as_view(), name="contactform"),
path("oidc/", include("mozilla_django_oidc.urls")),
path("digid-oidc/", include("open_inwoner.accounts.digid_urls")),
path("eherkenning-oidc/", include("open_inwoner.accounts.eherkenning_urls")),
Expand Down
Loading