From 09f122a0150d38b8f9a3b6b12f78c2cdb88e7d10 Mon Sep 17 00:00:00 2001 From: Nathan Victor Date: Thu, 19 Oct 2017 11:35:47 -0500 Subject: [PATCH 1/6] add messages for form submission message --- wagtailstreamforms/templates/streamforms/form_block.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 %}

{{ value.form.name }}

{% csrf_token %} @@ -6,4 +11,4 @@

{{ value.form.name }}

{% include 'streamforms/partials/form_field.html' %} {% endfor %} -
\ No newline at end of file + From ca877765ea2afed192ad9ba09143fbf1de253d48 Mon Sep 17 00:00:00 2001 From: Nathan Victor Date: Thu, 14 Dec 2017 17:53:47 -0600 Subject: [PATCH 2/6] privatizing the email submission response --- wagtailstreamforms/models/form.py | 34 ++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/wagtailstreamforms/models/form.py b/wagtailstreamforms/models/form.py index c749f28f..ee91989e 100644 --- a/wagtailstreamforms/models/form.py +++ b/wagtailstreamforms/models/form.py @@ -340,18 +340,28 @@ def process_form_submission(self, form): def send_form_mail(self, form): """ Send an email. """ - content = [self.message + '\n\nSubmission\n', ] - - for name, field in form.fields.items(): - data = form.cleaned_data.get(name) - - if name in self.ignored_fields or not data: - continue # pragma: no cover - - label = field.label or name - - content.append(label + ': ' + six.text_type(data)) - + # content = [self.message + '\n\nSubmission\n', ] + # + # for name, field in form.fields.items(): + # data = form.cleaned_data.get(name) + # + # if name in self.ignored_fields or not data: + # continue # pragma: no cover + # + # label = field.label or name + # + # content.append(label + ': ' + six.text_type(data)) + # keeping submissions out of email. just send a link to the forms. + + from django.urls import reverse + from django.contrib.sites.models import Site + 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) send_mail( self.subject, '\n'.join(content), From 47e024b2142057dd44b543c64cc0fb635863611d Mon Sep 17 00:00:00 2001 From: Nathan Victor Date: Fri, 15 Dec 2017 11:01:26 -0600 Subject: [PATCH 3/6] add field to exclude form data from email b/c privacy --- .../0009_emailform_exclude_form_data.py | 20 ++++++++++ wagtailstreamforms/models/form.py | 38 ++++++++++--------- 2 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 wagtailstreamforms/migrations/0009_emailform_exclude_form_data.py 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 ee91989e..578b1414 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=True, + 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,29 +344,26 @@ 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) - # - # if name in self.ignored_fields or not data: - # continue # pragma: no cover - # - # label = field.label or name - # - # content.append(label + ': ' + six.text_type(data)) - # keeping submissions out of email. just send a link to the forms. + 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) - from django.urls import reverse - from django.contrib.sites.models import Site - current_site = Site.objects.get_current().domain + else: + content = [self.message + '\n\nSubmission\n', ] + for name, field in form.fields.items(): + data = form.cleaned_data.get(name) - url = reverse('wagtailstreamforms:streamforms_submissions', args=[str(self.pk)]) + if name in self.ignored_fields or not data: + continue # pragma: no cover - content = [self.message + '\n\nYour form has a new submission.\n', ] + label = field.label or name + content.append(label + ': ' + six.text_type(data)) - content.append('To view the submission, go to: ' + current_site + url) send_mail( self.subject, '\n'.join(content), From b5005b2e647520dbbdc639149f9042662a797a96 Mon Sep 17 00:00:00 2001 From: Nathan Victor Date: Fri, 15 Dec 2017 11:34:22 -0600 Subject: [PATCH 4/6] added necessary settings for Site --- docs/installation.rst | 5 +++-- tests/settings.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 From 0e80ffc846cb38c7df05e756b20c407881f52b53 Mon Sep 17 00:00:00 2001 From: Nathan Victor Date: Fri, 15 Dec 2017 11:54:29 -0600 Subject: [PATCH 5/6] make flake8 happy. 'wagtailstreamforms/models/form.py:352:18: E222 multiple spaces after operator' --- wagtailstreamforms/models/form.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wagtailstreamforms/models/form.py b/wagtailstreamforms/models/form.py index 578b1414..77869c66 100644 --- a/wagtailstreamforms/models/form.py +++ b/wagtailstreamforms/models/form.py @@ -349,7 +349,7 @@ def send_form_mail(self, form): from django.contrib.sites.models import Site current_site = Site.objects.get_current().domain - url = reverse('wagtailstreamforms:streamforms_submissions', args=[str(self.pk)]) + 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) From 148557ed8b32058c3fe08b46ce96d1794c50cf1c Mon Sep 17 00:00:00 2001 From: Nathan Victor Date: Fri, 12 Jan 2018 16:38:16 -0600 Subject: [PATCH 6/6] changing form submission details in email to False --- wagtailstreamforms/models/form.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wagtailstreamforms/models/form.py b/wagtailstreamforms/models/form.py index 77869c66..b3e496a9 100644 --- a/wagtailstreamforms/models/form.py +++ b/wagtailstreamforms/models/form.py @@ -311,7 +311,7 @@ class AbstractEmailForm(BaseForm): ) message = models.TextField() exclude_form_data = models.BooleanField( - default=True, + default=False, help_text=_("Exclude form submission data from email") ) fail_silently = models.BooleanField(