]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
templates: Move additional email subjects to templates
authorStephen Finucane <stephen@that.guru>
Fri, 7 Sep 2018 11:17:04 +0000 (12:17 +0100)
committerStephen Finucane <stephen@that.guru>
Sat, 29 Sep 2018 21:41:16 +0000 (22:41 +0100)
Use a uniform pattern for this stuff.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/templates/patchwork/mails/optin-request-subject.txt [new file with mode: 0644]
patchwork/templates/patchwork/mails/optout-request-subject.txt [new file with mode: 0644]
patchwork/templates/patchwork/mails/user-link-subject.txt [new file with mode: 0644]
patchwork/views/mail.py
patchwork/views/user.py

diff --git a/patchwork/templates/patchwork/mails/optin-request-subject.txt b/patchwork/templates/patchwork/mails/optin-request-subject.txt
new file mode 100644 (file)
index 0000000..9733b6f
--- /dev/null
@@ -0,0 +1 @@
+Patchwork opt-in request
\ No newline at end of file
diff --git a/patchwork/templates/patchwork/mails/optout-request-subject.txt b/patchwork/templates/patchwork/mails/optout-request-subject.txt
new file mode 100644 (file)
index 0000000..377dfc8
--- /dev/null
@@ -0,0 +1 @@
+Patchwork opt-out confirmation
\ No newline at end of file
diff --git a/patchwork/templates/patchwork/mails/user-link-subject.txt b/patchwork/templates/patchwork/mails/user-link-subject.txt
new file mode 100644 (file)
index 0000000..8ac4d1d
--- /dev/null
@@ -0,0 +1 @@
+Patchwork email address confirmation
\ No newline at end of file
index 280f4e8cfb07b4f7675e836e49344602fb4b77b0..8d4de30e482394fb1e93f5ec1ff6cfd4068ede08 100644 (file)
@@ -67,9 +67,10 @@ def optin_confirm(request, conf):
     return render(request, 'patchwork/optin.html', context)
 
 
-def _optinout(request, action, description):
+def _optinout(request, action):
     context = {}
     mail_template = 'patchwork/mails/%s-request.txt' % action
+    mail_subject_template = 'patchwork/mails/%s-request-subject.txt' % action
     html_template = 'patchwork/%s-request.html' % action
 
     if request.method != 'POST':
@@ -77,8 +78,8 @@ def _optinout(request, action, description):
 
     form = EmailForm(data=request.POST)
     if not form.is_valid():
-        context['error'] = ('There was an error in the %s form. Please '
-                            'review the form and re-submit.' % description)
+        context['error'] = ('There was an error in the form. Please review '
+                            'and re-submit.')
         context['form'] = form
         return render(request, html_template, context)
 
@@ -95,11 +96,13 @@ def _optinout(request, action, description):
     conf.save()
 
     context['confirmation'] = conf
-    mail = render_to_string(mail_template, context, request=request)
+
+    subject = render_to_string(mail_subject_template)
+    message = render_to_string(mail_template, context, request=request)
 
     try:
-        send_mail('Patchwork %s confirmation' % description, mail,
-                  conf_settings.DEFAULT_FROM_EMAIL, [email])
+        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['error'] = ('An error occurred during confirmation . '
@@ -110,8 +113,8 @@ def _optinout(request, action, description):
 
 
 def optout(request):
-    return _optinout(request, 'optout', 'opt-out')
+    return _optinout(request, 'optout')
 
 
 def optin(request):
-    return _optinout(request, 'optin', 'opt-in')
+    return _optinout(request, 'optin')
index f3d8ae36dc4c7e8e6a02f1aa25518569b95b5578..21d2744beb879dd3f211b0a9d8549755bdbd843a 100644 (file)
@@ -138,7 +138,7 @@ def link(request):
 
             context['confirmation'] = conf
 
-            subject = 'Patchwork email address confirmation',
+            subject = render_to_string('patchwork/mails/user-link-subject.txt')
             message = render_to_string('patchwork/mails/user-link.txt',
                                        context, request=request)
             try: