diff --git a/docs/installation.rst b/docs/installation.rst index 2cf68d44..c907999b 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -4,7 +4,7 @@ Installation Wagtail Streamform is available on PyPI - to install it, just run: .. code-block:: python - + pip install wagtailstreamforms Once thats done you need to add the following to your ``INSTALLED_APPS`` settings: @@ -15,7 +15,8 @@ Once thats done you need to add the following to your ``INSTALLED_APPS`` setting ... 'wagtail.contrib.modeladmin', 'wagtail.wagtailforms', - 'wagtailstreamforms' + 'wagtailstreamforms', + 'django.contrib.sites', ... ] diff --git a/tests/settings.py b/tests/settings.py index db339ee2..b010f24a 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -10,7 +10,8 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - + 'django.contrib.sites', + # wagtail 'wagtail.wagtailcore', 'wagtail.wagtailadmin', @@ -74,3 +75,5 @@ STATIC_URL = '/static/' LOGIN_URL = reverse_lazy('admin:login') + +SITE_ID = 1 diff --git a/wagtailstreamforms/migrations/0009_emailform_exclude_form_data.py b/wagtailstreamforms/migrations/0009_emailform_exclude_form_data.py new file mode 100644 index 00000000..26b7dfc6 --- /dev/null +++ b/wagtailstreamforms/migrations/0009_emailform_exclude_form_data.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2017-12-15 16:43 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailstreamforms', '0008_baseform_content_type_not_null'), + ] + + operations = [ + migrations.AddField( + model_name='emailform', + name='exclude_form_data', + field=models.BooleanField(default=True, help_text='Exclude form submission data from email'), + ), + ] diff --git a/wagtailstreamforms/models/form.py b/wagtailstreamforms/models/form.py index c749f28f..b3e496a9 100644 --- a/wagtailstreamforms/models/form.py +++ b/wagtailstreamforms/models/form.py @@ -310,6 +310,10 @@ class AbstractEmailForm(BaseForm): help_text=_("Add one email per line") ) message = models.TextField() + exclude_form_data = models.BooleanField( + default=False, + help_text=_("Exclude form submission data from email") + ) fail_silently = models.BooleanField( default=True ) @@ -319,6 +323,7 @@ class AbstractEmailForm(BaseForm): FieldPanel('from_address', classname="full"), FieldPanel('to_addresses', classname="full"), FieldPanel('message', classname="full"), + FieldPanel('exclude_form_data'), FieldPanel('fail_silently'), ] @@ -339,18 +344,25 @@ def process_form_submission(self, form): def send_form_mail(self, form): """ Send an email. """ + if self.exclude_form_data: + from django.urls import reverse + from django.contrib.sites.models import Site - content = [self.message + '\n\nSubmission\n', ] - - for name, field in form.fields.items(): - data = form.cleaned_data.get(name) + current_site = Site.objects.get_current().domain + url = reverse('wagtailstreamforms:streamforms_submissions', args=[str(self.pk)]) + content = [self.message + '\n\nYour form has a new submission.\n', ] + content.append('To view the submission, go to: ' + current_site + url) - if name in self.ignored_fields or not data: - continue # pragma: no cover + else: + content = [self.message + '\n\nSubmission\n', ] + for name, field in form.fields.items(): + data = form.cleaned_data.get(name) - label = field.label or name + if name in self.ignored_fields or not data: + continue # pragma: no cover - content.append(label + ': ' + six.text_type(data)) + label = field.label or name + content.append(label + ': ' + six.text_type(data)) send_mail( self.subject, diff --git a/wagtailstreamforms/templates/streamforms/form_block.html b/wagtailstreamforms/templates/streamforms/form_block.html index 4c406cba..2d459f9d 100644 --- a/wagtailstreamforms/templates/streamforms/form_block.html +++ b/wagtailstreamforms/templates/streamforms/form_block.html @@ -1,3 +1,8 @@ +{% if messages %} + {% for message in messages %} +
{{ message }}
+ {% endfor %} +{% endif %}