diff options
author | Stephen Finucane <stephen@that.guru> | 2018-09-07 12:17:04 +0100 |
---|---|---|
committer | Stephen Finucane <stephen@that.guru> | 2018-09-29 22:41:16 +0100 |
commit | 45fa5c5c9ff81cbe5aca16c7a9841adacf921edd (patch) | |
tree | 9c8eac1cfd90cd3c650500220f91d68fbe4e0f6b /patchwork/views | |
parent | 25c13ef14e55d664cfb2c1abe0eaf8e3288e7c00 (diff) | |
download | patchwork-45fa5c5c9ff81cbe5aca16c7a9841adacf921edd.tar patchwork-45fa5c5c9ff81cbe5aca16c7a9841adacf921edd.tar.gz |
templates: Move additional email subjects to templates
Use a uniform pattern for this stuff.
Signed-off-by: Stephen Finucane <stephen@that.guru>
Diffstat (limited to 'patchwork/views')
-rw-r--r-- | patchwork/views/mail.py | 19 | ||||
-rw-r--r-- | patchwork/views/user.py | 2 |
2 files changed, 12 insertions, 9 deletions
diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py index 280f4e8..8d4de30 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 f3d8ae3..21d2744 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: |