diff --git a/mpicms/base/models.py b/mpicms/base/models.py index 6bdc226..c6522cf 100644 --- a/mpicms/base/models.py +++ b/mpicms/base/models.py @@ -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 @@ -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 + ) diff --git a/mpicms/templates/base/form_page.html b/mpicms/templates/base/form_page.html new file mode 100644 index 0000000..57a5e42 --- /dev/null +++ b/mpicms/templates/base/form_page.html @@ -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 %} diff --git a/mpicms/templates/base/form_page_landing.html b/mpicms/templates/base/form_page_landing.html new file mode 100644 index 0000000..dd2bb69 --- /dev/null +++ b/mpicms/templates/base/form_page_landing.html @@ -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 %}