[PATCH 5/6] templates: Remove 'email_sent' attribute
Stephen Finucane
stephen at that.guru
Tue Sep 18 00:17:49 AEST 2018
Further normalization to ensure all related code paths use similar code.
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
patchwork/templates/patchwork/optin-request.html | 2 +-
patchwork/templates/patchwork/optout-request.html | 2 +-
patchwork/tests/test_mail_settings.py | 8 ++++----
patchwork/views/mail.py | 7 +++----
4 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/patchwork/templates/patchwork/optin-request.html b/patchwork/templates/patchwork/optin-request.html
index dfc104e8..90963e65 100644
--- a/patchwork/templates/patchwork/optin-request.html
+++ b/patchwork/templates/patchwork/optin-request.html
@@ -4,7 +4,7 @@
{% block heading %}Opt-in{% endblock %}
{% block body %}
-{% if email_sent %}
+{% if confirmation %}
<p><strong>Opt-in confirmation email sent</strong></p>
<p>An opt-in confirmation mail has been sent to
<strong>{{confirmation.email}}</strong>, containing a link. Please click on
diff --git a/patchwork/templates/patchwork/optout-request.html b/patchwork/templates/patchwork/optout-request.html
index eae05e62..659af773 100644
--- a/patchwork/templates/patchwork/optout-request.html
+++ b/patchwork/templates/patchwork/optout-request.html
@@ -4,7 +4,7 @@
{% block heading %}Opt-out{% endblock %}
{% block body %}
-{% if email_sent %}
+{% if confirmation %}
<p><strong>Opt-out confirmation email sent</strong></p>
<p>An opt-out confirmation mail has been sent to
<strong>{{confirmation.email}}</strong>, containing a link. Please click on
diff --git a/patchwork/tests/test_mail_settings.py b/patchwork/tests/test_mail_settings.py
index 70e135d5..8844212e 100644
--- a/patchwork/tests/test_mail_settings.py
+++ b/patchwork/tests/test_mail_settings.py
@@ -108,7 +108,7 @@ class OptoutRequestTest(TestCase):
self.assertFormError(response, 'form', 'email',
'This field is required.')
self.assertTrue(response.context['error'])
- self.assertNotIn('email_sent', response.context)
+ self.assertNotIn('confirmation', response.context)
self.assertEqual(len(mail.outbox), 0)
def test_post_non_email(self):
@@ -116,7 +116,7 @@ class OptoutRequestTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', 'email', error_strings['email'])
self.assertTrue(response.context['error'])
- self.assertNotIn('email_sent', response.context)
+ self.assertNotIn('confirmation', response.context)
self.assertEqual(len(mail.outbox), 0)
@@ -189,7 +189,7 @@ class OptinRequestTest(TestCase):
self.assertFormError(response, 'form', 'email',
'This field is required.')
self.assertTrue(response.context['error'])
- self.assertNotIn('email_sent', response.context)
+ self.assertNotIn('confirmation', response.context)
self.assertEqual(len(mail.outbox), 0)
def test_post_non_email(self):
@@ -197,7 +197,7 @@ class OptinRequestTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertFormError(response, 'form', 'email', error_strings['email'])
self.assertTrue(response.context['error'])
- self.assertNotIn('email_sent', response.context)
+ self.assertNotIn('confirmation', response.context)
self.assertEqual(len(mail.outbox), 0)
diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py
index 1ce37736..6a3c1c25 100644
--- a/patchwork/views/mail.py
+++ b/patchwork/views/mail.py
@@ -97,8 +97,8 @@ def _optinout(request, action):
return render(request, html_template, context)
email = form.cleaned_data['email']
- if action == 'optin' and \
- EmailOptout.objects.filter(email=email).count() == 0:
+ if action == 'optin' and EmailOptout.objects.filter(
+ email=email).count() == 0:
context['error'] = ("The email address %s is not on the patchwork "
"opt-out list, so you don't need to opt back in" %
email)
@@ -115,9 +115,8 @@ def _optinout(request, action):
try:
send_mail(subject, message, conf_settings.DEFAULT_FROM_EMAIL, [email])
- # TODO(stephenfin): This is unnecessary and can be removed
- context['email_sent'] = True
except smtplib.SMTPException:
+ context['confirmation'] = None
context['error'] = ('An error occurred during confirmation . '
'Please try again later.')
context['admins'] = conf_settings.ADMINS
--
2.17.1
More information about the Patchwork
mailing list