From patchwork Mon Sep 17 14:17:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 970609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42DStp2byVz9sfR for ; Tue, 18 Sep 2018 00:19:46 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="jru8SNwm"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42DStp0vw3zF31F for ; Tue, 18 Sep 2018 00:19:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="jru8SNwm"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.6; helo=relay-direct6.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="jru8SNwm"; dkim-atps=neutral Received: from relay-direct6.mxroute.com (relay-direct6.mxroute.com [185.234.75.6]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42DSsP2bMszF2QM for ; Tue, 18 Sep 2018 00:18:32 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct6.mxroute.com (Postfix) with ESMTP id 99DDF3F357 for ; Mon, 17 Sep 2018 14:18:00 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 818C83F3E0 for ; Mon, 17 Sep 2018 14:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=W25Qn9nFYvVjrJ//jp/71+htu0BEnEa/yOQRrxnZNSI=; b=jru8SNwmHvBVtLoUdgxHK62ajg 6MJi5sCXRNAsePOv/HK5hdSJBzXDnj6LKh9NFPUufUoPMBD8jwU/5UnW6xtDZ66B4Ercibt7D5Pz6 c3+PY9JlqJ13d76d9shKv6sJB869k8a5ZaSIW4nU8+0F0If2QhlA6xzOkiStnLaKxxcnRNgGNZNAk 2z5K2ZrBax9mPSQi50qfFWv/w2w3S/VAxvagTDCjGhP/h/RD7bqkJgjiOHSzdUzJKYXAqvLN5T7pK guIpdVQtSF3njdlTXLaF5TxwPub6NkTiyXuTVQlvxJi2rzp23610VQLbOdgGD8r4oj7nM5w/51/rg U5jXCmYg==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 4/6] templates: Move additional email subjects to templates Date: Mon, 17 Sep 2018 15:17:48 +0100 Message-Id: <20180917141750.21508-4-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180917141750.21508-1-stephen@that.guru> References: <20180917141750.21508-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Use a uniform pattern for this stuff. Signed-off-by: Stephen Finucane --- .../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: