Skip to content

Adding choice to exclude form submission data from email notifications #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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',
...
]

Expand Down
5 changes: 4 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'django.contrib.sites',

# wagtail
'wagtail.wagtailcore',
'wagtail.wagtailadmin',
Expand Down Expand Up @@ -74,3 +75,5 @@
STATIC_URL = '/static/'

LOGIN_URL = reverse_lazy('admin:login')

SITE_ID = 1
20 changes: 20 additions & 0 deletions wagtailstreamforms/migrations/0009_emailform_exclude_form_data.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
28 changes: 20 additions & 8 deletions wagtailstreamforms/models/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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'),
]

Expand All @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion wagtailstreamforms/templates/streamforms/form_block.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{% if messages %}
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
{% endif %}
<h2>{{ value.form.name }}</h2>
<form action="{{ value.form_action }}" method="post" novalidate>
{% csrf_token %}
Expand All @@ -6,4 +11,4 @@ <h2>{{ value.form.name }}</h2>
{% include 'streamforms/partials/form_field.html' %}
{% endfor %}
<input type="submit" value="{{ value.form.submit_button_text }}">
</form>
</form>