[PATCH 4/6] templates: Move additional email subjects to templates
Stephen Finucane
stephen at that.guru
Tue Sep 18 00:17:48 AEST 2018
Use a uniform pattern for this stuff.
Signed-off-by: Stephen Finucane <stephen at that.guru>
---
.../patchwork/mails/optin-request-subject.txt | 1 +
.../mails/optout-request-subject.txt | 1 +
.../patchwork/mails/user-link-subject.txt | 1 +
patchwork/views/mail.py | 19 +++++++++++--------
patchwork/views/user.py | 2 +-
5 files changed, 15 insertions(+), 9 deletions(-)
create mode 100644 patchwork/templates/patchwork/mails/optin-request-subject.txt
create mode 100644 patchwork/templates/patchwork/mails/optout-request-subject.txt
create mode 100644 patchwork/templates/patchwork/mails/user-link-subject.txt
diff --git a/patchwork/templates/patchwork/mails/optin-request-subject.txt b/patchwork/templates/patchwork/mails/optin-request-subject.txt
new file mode 100644
index 00000000..9733b6f3
--- /dev/null
+++ b/patchwork/templates/patchwork/mails/optin-request-subject.txt
@@ -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
index 00000000..377dfc89
--- /dev/null
+++ b/patchwork/templates/patchwork/mails/optout-request-subject.txt
@@ -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
index 00000000..8ac4d1d4
--- /dev/null
+++ b/patchwork/templates/patchwork/mails/user-link-subject.txt
@@ -0,0 +1 @@
+Patchwork email address confirmation
\ No newline at end of file
diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py
index 12825a13..1ce37736 100644
--- a/patchwork/views/mail.py
+++ b/patchwork/views/mail.py
@@ -80,9 +80,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':
@@ -90,8 +91,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)
@@ -108,11 +109,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 . '
@@ -123,8 +126,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')
diff --git a/patchwork/views/user.py b/patchwork/views/user.py
index cb8e61af..6348bed6 100644
--- a/patchwork/views/user.py
+++ b/patchwork/views/user.py
@@ -151,7 +151,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:
--
2.17.1
More information about the Patchwork
mailing list