Skip to content

Commit

Permalink
[#2856] Make contact form plugin configurable via CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Nov 27, 2024
1 parent b534838 commit a049f00
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@
"ProductLocationPlugin",
"UserFeedPlugin",
"UserAppointmentsPlugin",
"ContactFormPlugin",
],
"text_only_plugins": ["LinkPlugin"],
"name": _("Content"),
Expand Down Expand Up @@ -615,10 +616,6 @@
"TextPlugin": ["LinkPlugin"],
},
},
"contact_form": {
"name": _("Contact form plugin"),
"plugins": ["ContactFormPlugin"],
},
}

CMS_TOOLBAR_ANONYMOUS_ON = False
Expand Down
25 changes: 25 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 @@ -37,3 +45,20 @@ class ContactFormPlugin(CMSPluginBase):
name = _("Contact form plugin")
render_template = "pages/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"
),
),
]

0 comments on commit a049f00

Please sign in to comment.