]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
templates: Remove 'email_sent' attribute
authorStephen Finucane <stephen@that.guru>
Fri, 7 Sep 2018 11:28:23 +0000 (12:28 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 29 Sep 2018 21:41:16 +0000 (22:41 +0100)
Further normalization to ensure all related code paths use similar code.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/templates/patchwork/optin-request.html
patchwork/templates/patchwork/optout-request.html
patchwork/tests/test_mail_settings.py
patchwork/views/mail.py

index dfc104e8b2db7f0a62c7bdbb272c7403df8db22b..90963e65dd32a8b739d073bfea99fb3de1ca7bee 100644 (file)
@@ -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
index eae05e62005bf8bcdf0fdbe520bf21e8ffd9520a..659af773925cf1c5b3988af966ae96f0435644c6 100644 (file)
@@ -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
index 34b3f8685f6edea77501a9bd0d90bc74f770cd69..78cbd6dbccfdf956f95c241b38103382d2417117 100644 (file)
@@ -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)
 
 
index 8d4de30e482394fb1e93f5ec1ff6cfd4068ede08..4bc7be0fb96551d1c8723b7dfad091ce43dc86ef 100644 (file)
@@ -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