From: Stephen Finucane Date: Fri, 7 Sep 2018 11:28:23 +0000 (+0100) Subject: templates: Remove 'email_sent' attribute X-Git-Tag: v2.2.0-rc1~267 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dadb156c60448687e75dd861d2253a3624be554d;p=thirdparty%2Fpatchwork.git templates: Remove 'email_sent' attribute Further normalization to ensure all related code paths use similar code. Signed-off-by: Stephen Finucane --- 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 %}

Opt-in confirmation email sent

An opt-in confirmation mail has been sent to {{confirmation.email}}, 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 %}

Opt-out confirmation email sent

An opt-out confirmation mail has been sent to {{confirmation.email}}, containing a link. Please click on diff --git a/patchwork/tests/test_mail_settings.py b/patchwork/tests/test_mail_settings.py index 34b3f868..78cbd6db 100644 --- a/patchwork/tests/test_mail_settings.py +++ b/patchwork/tests/test_mail_settings.py @@ -95,7 +95,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): @@ -103,7 +103,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) @@ -176,7 +176,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): @@ -184,7 +184,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 8d4de30e..4bc7be0f 100644 --- a/patchwork/views/mail.py +++ b/patchwork/views/mail.py @@ -84,8 +84,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) @@ -102,9 +102,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