Skip to content

Commit

Permalink
Add FormPage page type
Browse files Browse the repository at this point in the history
Add FormPage page type using [Wagtail Form Builder].

[Wagtail Form Builder]: https://docs.wagtail.io/en/v2.0/reference/contrib/forms/index.html
  • Loading branch information
donald committed Mar 8, 2020
1 parent 1ba838f commit 2458820
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
32 changes: 31 additions & 1 deletion mpicms/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.snippets.edit_handlers import SnippetChooserPanel
from wagtail.snippets.models import register_snippet
from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.admin.edit_handlers import (
StreamFieldPanel, InlinePanel, MultiFieldPanel, FieldRowPanel,
)
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.core.fields import StreamField
from wagtail.search import index
from wagtail.contrib.forms.models import AbstractEmailForm, AbstractFormField
from wagtail.contrib.forms.edit_handlers import FormSubmissionsPanel
from modelcluster.fields import ParentalKey

from mpicms.news.mixins import NewsMixin
from mpicms.events.mixins import EventMixin
Expand Down Expand Up @@ -137,3 +142,28 @@ def serve(self, request, *args, **kwargs):

def serve_preview(self, request, mode_name):
return ContactListView.as_view()(request)

class FormField(AbstractFormField):
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')

class FormPage(AbstractEmailForm, SideBarMixin, BasePage):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)

content_panels = (
AbstractEmailForm.content_panels +
[
FormSubmissionsPanel(),
FieldPanel('intro', classname="full"),
InlinePanel('form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email"),
] +
SideBarMixin.content_panels
)
22 changes: 22 additions & 0 deletions mpicms/templates/base/form_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'base/page.html' %}

{% load wagtailcore_tags static %}

{% block head %}
{{ block.super }}
{% endblock %}

{% block page_content %}
<h2 class="title is-2">{{ page.title }}</h2>

<div id="content" class="content">
{{ page.intro|richtext }}
<form action="{% pageurl page %}" method="POST">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit">
</form>
</div>
{% endblock %}
15 changes: 15 additions & 0 deletions mpicms/templates/base/form_page_landing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'base/page.html' %}

{% load wagtailcore_tags static %}

{% block head %}
{{ block.super }}
{% endblock %}

{% block page_content %}
<h2 class="title is-2">{{ page.title }}</h2>

<div id="content" class="content">
{{ page.thank_you_text|richtext }}
</div>
{% endblock %}

0 comments on commit 2458820

Please sign in to comment.