Contact form model
This commit is contained in:
parent
8e5ef47d4c
commit
e5f3f63950
6 changed files with 179 additions and 0 deletions
|
@ -0,0 +1,55 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.6 on 2017-04-08 13:35
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import modelcluster.fields
|
||||
import wagtail.wagtailcore.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0033_auto_20170313_1755'),
|
||||
('home', '0011_contact_title'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ContactForm',
|
||||
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')),
|
||||
('title_fr', models.CharField(default=b'', max_length=255)),
|
||||
('intro_de', wagtail.wagtailcore.fields.RichTextField(blank=True, default=b'')),
|
||||
('intro_fr', wagtail.wagtailcore.fields.RichTextField(blank=True, default=b'')),
|
||||
('thanks_de', wagtail.wagtailcore.fields.RichTextField(blank=True, default=b'')),
|
||||
('thanks_fr', wagtail.wagtailcore.fields.RichTextField(blank=True, default=b'')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
bases=('wagtailcore.page',),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ContactFormField',
|
||||
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'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time')], 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='home.ContactForm')),
|
||||
],
|
||||
options={
|
||||
'ordering': ['sort_order'],
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
59
publichealth/home/models/forms.py
Normal file
59
publichealth/home/models/forms.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from modelcluster.fields import ParentalKey
|
||||
|
||||
from wagtail.wagtailadmin.edit_handlers import (
|
||||
FieldPanel, FieldRowPanel,
|
||||
InlinePanel, MultiFieldPanel
|
||||
)
|
||||
|
||||
from django.db.models import CharField
|
||||
from wagtail.wagtailcore.fields import RichTextField
|
||||
from wagtail.wagtailforms.models import (
|
||||
AbstractEmailForm, AbstractFormField
|
||||
)
|
||||
|
||||
from ..util import TranslatedField
|
||||
|
||||
class ContactFormField(AbstractFormField):
|
||||
page = ParentalKey('ContactForm', related_name='form_fields')
|
||||
|
||||
class ContactForm(AbstractEmailForm):
|
||||
title_fr = CharField(max_length=255, default="")
|
||||
trans_title = TranslatedField(
|
||||
'title',
|
||||
'title_fr',
|
||||
)
|
||||
|
||||
intro_de = RichTextField(default='', blank=True)
|
||||
intro_fr = RichTextField(default='', blank=True)
|
||||
trans_intro = TranslatedField(
|
||||
'intro_de',
|
||||
'intro_fr',
|
||||
)
|
||||
|
||||
thanks_de = RichTextField(default='', blank=True)
|
||||
thanks_fr = RichTextField(default='', blank=True)
|
||||
trans_thanks = TranslatedField(
|
||||
'thanks_de',
|
||||
'thanks_fr',
|
||||
)
|
||||
|
||||
content_panels = AbstractEmailForm.content_panels + [
|
||||
FieldPanel('intro_de', classname="full"),
|
||||
FieldPanel('thanks_de', classname="full"),
|
||||
FieldPanel('title_fr', classname="full"),
|
||||
FieldPanel('intro_fr', classname="full"),
|
||||
FieldPanel('thanks_fr', classname="full"),
|
||||
InlinePanel('form_fields', label="Form fields"),
|
||||
MultiFieldPanel([
|
||||
FieldRowPanel([
|
||||
FieldPanel('from_address', classname="col6"),
|
||||
FieldPanel('to_address', classname="col6"),
|
||||
]),
|
||||
FieldPanel('subject'),
|
||||
], "Email"),
|
||||
]
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Formular"
|
24
publichealth/home/templates/home/contact_form.html
Normal file
24
publichealth/home/templates/home/contact_form.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% extends "base.html" %}
|
||||
{% load wagtailcore_tags %}
|
||||
|
||||
{% block body_class %}template-{{ self.get_verbose_name|slugify }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section id="contact-page">
|
||||
<div class="container">
|
||||
|
||||
<h2>{{ page.trans_title }}</h2>
|
||||
|
||||
<p class="lead">{{ page.trans_intro|richtext }}</p>
|
||||
|
||||
<!-- Main content -->
|
||||
<div class="article-body" role="main">
|
||||
<form action="{% pageurl page %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button class="btn btn-primary" type="submit">Senden / Envoi</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
17
publichealth/home/templates/home/contact_form_landing.html
Normal file
17
publichealth/home/templates/home/contact_form_landing.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
{% extends "base.html" %}
|
||||
{% load wagtailcore_tags %}
|
||||
|
||||
{% block body_class %}template-{{ self.get_verbose_name|slugify }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section id="contact-page">
|
||||
<div class="container">
|
||||
|
||||
<h2>{{ page.trans_title }}</h2>
|
||||
|
||||
<center>
|
||||
<p class="lead">{{ page.trans_thanks|richtext }}</p>
|
||||
</center>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
12
publichealth/home/templates/tags/contact_form.html
Normal file
12
publichealth/home/templates/tags/contact_form.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<form action="https://formspree.io/{{ contact.email }}" method="POST">
|
||||
<div class="form-group">
|
||||
<input name="name" id="name" type="text" placeholder="Name / Nom" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input name="_replyto" id="email" type="email" placeholder="E-Mail" class="form-control">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<textarea name="message" id="message" rows="3" placeholder="" class="form-control"></textarea>
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">Senden / Envoi</button>
|
||||
</form>
|
12
publichealth/static/css/modules/_forms.scss
Normal file
12
publichealth/static/css/modules/_forms.scss
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Contact form
|
||||
#contact-page {
|
||||
|
||||
form {
|
||||
label {
|
||||
width: 15em;
|
||||
border-bottom: 1px dashed #ccc;
|
||||
line-height: 155%;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue