From: Stephen Finucane Date: Fri, 7 Sep 2018 11:17:04 +0000 (+0100) Subject: templates: Move additional email subjects to templates X-Git-Tag: v2.2.0-rc1~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45fa5c5c9ff81cbe5aca16c7a9841adacf921edd;p=thirdparty%2Fpatchwork.git templates: Move additional email subjects to templates Use a uniform pattern for this stuff. Signed-off-by: Stephen Finucane --- 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 280f4e8c..8d4de30e 100644 --- a/patchwork/views/mail.py +++ b/patchwork/views/mail.py @@ -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') diff --git a/patchwork/views/user.py b/patchwork/views/user.py index f3d8ae36..21d2744b 100644 --- a/patchwork/views/user.py +++ b/patchwork/views/user.py @@ -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: