Skip to content

Commit

Permalink
Merge pull request #78 from molgen/add-wagtailforms-v3
Browse files Browse the repository at this point in the history
Add wagtailforms v3
  • Loading branch information
donald authored Mar 8, 2020
2 parents 1ba838f + d909f22 commit 9d3a325
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 2 deletions.
62 changes: 62 additions & 0 deletions mpicms/base/migrations/0051_formfield_formpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generated by Django 2.2.9 on 2020-03-08 19:09

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields
import wagtail.core.blocks
import wagtail.core.fields
import wagtail.snippets.blocks


class Migration(migrations.Migration):

dependencies = [
('wagtailcore', '0041_group_collection_permissions_verbose_name_plural'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('base', '0050_auto_20200119_1857'),
]

operations = [
migrations.CreateModel(
name='FormPage',
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('to_address', models.CharField(blank=True, help_text='Optional - form submissions will be emailed to these addresses. Separate multiple addresses by comma.', max_length=255, verbose_name='to address')),
('from_address', models.CharField(blank=True, max_length=255, verbose_name='from address')),
('subject', models.CharField(blank=True, max_length=255, verbose_name='subject')),
('sidebar', wagtail.core.fields.StreamField([('editor', wagtail.core.blocks.RichTextBlock(features=['h4', 'h5', 'h6', 'bold', 'italic', 'link', 'document-link'], label='Editor')), ('contacts', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('contact', wagtail.snippets.blocks.SnippetChooserBlock('personal.Contact', label='Contact')), ('information', wagtail.core.blocks.TextBlock(label='Information', required=False))]), icon='user', label='Contacts', template='base/blocks/contact_list_block.html'))], blank=True, verbose_name='Sidebar Content')),
('sidebar_en', wagtail.core.fields.StreamField([('editor', wagtail.core.blocks.RichTextBlock(features=['h4', 'h5', 'h6', 'bold', 'italic', 'link', 'document-link'], label='Editor')), ('contacts', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('contact', wagtail.snippets.blocks.SnippetChooserBlock('personal.Contact', label='Contact')), ('information', wagtail.core.blocks.TextBlock(label='Information', required=False))]), icon='user', label='Contacts', template='base/blocks/contact_list_block.html'))], blank=True, null=True, verbose_name='Sidebar Content')),
('sidebar_de', wagtail.core.fields.StreamField([('editor', wagtail.core.blocks.RichTextBlock(features=['h4', 'h5', 'h6', 'bold', 'italic', 'link', 'document-link'], label='Editor')), ('contacts', wagtail.core.blocks.ListBlock(wagtail.core.blocks.StructBlock([('contact', wagtail.snippets.blocks.SnippetChooserBlock('personal.Contact', label='Contact')), ('information', wagtail.core.blocks.TextBlock(label='Information', required=False))]), icon='user', label='Contacts', template='base/blocks/contact_list_block.html'))], blank=True, null=True, verbose_name='Sidebar Content')),
('intro', wagtail.core.fields.RichTextField(blank=True)),
('intro_en', wagtail.core.fields.RichTextField(blank=True, null=True)),
('intro_de', wagtail.core.fields.RichTextField(blank=True, null=True)),
('thank_you_text', wagtail.core.fields.RichTextField(blank=True)),
('thank_you_text_en', wagtail.core.fields.RichTextField(blank=True, null=True)),
('thank_you_text_de', wagtail.core.fields.RichTextField(blank=True, null=True)),
('subscribers', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
bases=('wagtailcore.page',),
),
migrations.CreateModel(
name='FormField',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
('label', models.CharField(help_text='The label of the form field', max_length=255, verbose_name='label')),
('field_type', models.CharField(choices=[('singleline', 'Single line text'), ('multiline', 'Multi-line text'), ('email', 'Email'), ('number', 'Number'), ('url', 'URL'), ('checkbox', 'Checkbox'), ('checkboxes', 'Checkboxes'), ('dropdown', 'Drop down'), ('multiselect', 'Multiple select'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time'), ('hidden', 'Hidden field')], max_length=16, verbose_name='field type')),
('required', models.BooleanField(default=True, verbose_name='required')),
('choices', models.TextField(blank=True, help_text='Comma separated list of choices. Only applicable in checkboxes, radio and dropdown.', verbose_name='choices')),
('default_value', models.CharField(blank=True, help_text='Default value. Comma separated values supported for checkboxes.', max_length=255, verbose_name='default value')),
('help_text', models.CharField(blank=True, max_length=255, verbose_name='help text')),
('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='form_fields', to='base.FormPage')),
],
options={
'ordering': ['sort_order'],
'abstract': False,
},
),
]
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
)
12 changes: 11 additions & 1 deletion mpicms/base/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from modeltranslation.translator import TranslationOptions
from modeltranslation.decorators import register

from .models import WikiPage, RootPage, HomePage, FeaturedImage, PhonelistPage
from .models import (
WikiPage, RootPage, HomePage, FeaturedImage, PhonelistPage,
FormPage, FormField,
)


@register(FeaturedImage)
Expand Down Expand Up @@ -43,3 +46,10 @@ class PhonelistPageTR(TranslationOptions):
fields = (
)

@register(FormPage)
class FormPageTR(TranslationOptions):
fields = (
'sidebar',
'intro',
'thank_you_text',
)
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 9d3a325

Please sign in to comment.