[PATCH 1/6] templates: Move mails to separate directory

Stephen Finucane stephen at that.guru
Tue Sep 18 00:17:45 AEST 2018


This makes things a little easier to parse. A couple of templates are
renamed and the 'register.mail' template, which appears to be unused
since commit f1e089f7, is removed.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/notifications.py                         |  7 ++++---
 .../activation-subject.txt}                        |  0
 .../{activation_email.txt => mails/activation.txt} |  0
 .../optin-request.txt}                             |  0
 .../optout-request.txt}                            |  0
 .../patch-change-notification-subject.txt}         |  0
 .../patch-change-notification.txt}                 |  0
 .../{user-link.mail => mails/user-link.txt}        |  0
 patchwork/templates/patchwork/register.mail        | 11 -----------
 patchwork/views/mail.py                            |  2 +-
 patchwork/views/user.py                            | 14 +++++++++-----
 11 files changed, 14 insertions(+), 20 deletions(-)
 rename patchwork/templates/patchwork/{activation_email_subject.txt => mails/activation-subject.txt} (100%)
 rename patchwork/templates/patchwork/{activation_email.txt => mails/activation.txt} (100%)
 rename patchwork/templates/patchwork/{optin-request.mail => mails/optin-request.txt} (100%)
 rename patchwork/templates/patchwork/{optout-request.mail => mails/optout-request.txt} (100%)
 rename patchwork/templates/patchwork/{patch-change-notification-subject.text => mails/patch-change-notification-subject.txt} (100%)
 rename patchwork/templates/patchwork/{patch-change-notification.mail => mails/patch-change-notification.txt} (100%)
 rename patchwork/templates/patchwork/{user-link.mail => mails/user-link.txt} (100%)
 delete mode 100644 patchwork/templates/patchwork/register.mail

diff --git a/patchwork/notifications.py b/patchwork/notifications.py
index 3ddd806b..45c081b9 100644
--- a/patchwork/notifications.py
+++ b/patchwork/notifications.py
@@ -76,10 +76,11 @@ def send_notifications():
         }
 
         subject = render_to_string(
-            'patchwork/patch-change-notification-subject.text',
+            'patchwork/mails/patch-change-notification-subject.txt',
             context).strip()
-        content = render_to_string('patchwork/patch-change-notification.mail',
-                                   context)
+        content = render_to_string(
+            'patchwork/mails/patch-change-notification.txt',
+            context)
 
         message = EmailMessage(subject=subject, body=content,
                                from_email=settings.NOTIFICATION_FROM_EMAIL,
diff --git a/patchwork/templates/patchwork/activation_email_subject.txt b/patchwork/templates/patchwork/mails/activation-subject.txt
similarity index 100%
rename from patchwork/templates/patchwork/activation_email_subject.txt
rename to patchwork/templates/patchwork/mails/activation-subject.txt
diff --git a/patchwork/templates/patchwork/activation_email.txt b/patchwork/templates/patchwork/mails/activation.txt
similarity index 100%
rename from patchwork/templates/patchwork/activation_email.txt
rename to patchwork/templates/patchwork/mails/activation.txt
diff --git a/patchwork/templates/patchwork/optin-request.mail b/patchwork/templates/patchwork/mails/optin-request.txt
similarity index 100%
rename from patchwork/templates/patchwork/optin-request.mail
rename to patchwork/templates/patchwork/mails/optin-request.txt
diff --git a/patchwork/templates/patchwork/optout-request.mail b/patchwork/templates/patchwork/mails/optout-request.txt
similarity index 100%
rename from patchwork/templates/patchwork/optout-request.mail
rename to patchwork/templates/patchwork/mails/optout-request.txt
diff --git a/patchwork/templates/patchwork/patch-change-notification-subject.text b/patchwork/templates/patchwork/mails/patch-change-notification-subject.txt
similarity index 100%
rename from patchwork/templates/patchwork/patch-change-notification-subject.text
rename to patchwork/templates/patchwork/mails/patch-change-notification-subject.txt
diff --git a/patchwork/templates/patchwork/patch-change-notification.mail b/patchwork/templates/patchwork/mails/patch-change-notification.txt
similarity index 100%
rename from patchwork/templates/patchwork/patch-change-notification.mail
rename to patchwork/templates/patchwork/mails/patch-change-notification.txt
diff --git a/patchwork/templates/patchwork/user-link.mail b/patchwork/templates/patchwork/mails/user-link.txt
similarity index 100%
rename from patchwork/templates/patchwork/user-link.mail
rename to patchwork/templates/patchwork/mails/user-link.txt
diff --git a/patchwork/templates/patchwork/register.mail b/patchwork/templates/patchwork/register.mail
deleted file mode 100644
index 51f3adfa..00000000
--- a/patchwork/templates/patchwork/register.mail
+++ /dev/null
@@ -1,11 +0,0 @@
-Hi,
-
-This email is to confirm your account on the Patchwork patch-tracking
-system. You can activate your account by visiting the url:
-
- http://{{site.domain}}{% url 'registration_activateactivation_key'=request.key %}
-
-If you didn't request a user account on Patchwork, then you can ignore
-this mail.
-
-Happy patchworking.
diff --git a/patchwork/views/mail.py b/patchwork/views/mail.py
index fab141d7..45283eba 100644
--- a/patchwork/views/mail.py
+++ b/patchwork/views/mail.py
@@ -82,7 +82,7 @@ def optin_confirm(request, conf):
 
 def _optinout(request, action, description):
     context = {}
-    mail_template = 'patchwork/%s-request.mail' % action
+    mail_template = 'patchwork/mails/%s-request.txt' % action
     html_template = 'patchwork/%s-request.html' % action
 
     if request.method != 'POST':
diff --git a/patchwork/views/user.py b/patchwork/views/user.py
index 1204baeb..848f86e5 100644
--- a/patchwork/views/user.py
+++ b/patchwork/views/user.py
@@ -65,11 +65,13 @@ def register(request):
             conf.save()
 
             # send email
-            subject = 'Patchwork account confirmation'
+            subject = render_to_string(
+                'patchwork/mails/activation-subject.txt')
             message = render_to_string(
-                'patchwork/activation_email.txt',
+                'patchwork/mails/activation.txt',
                 {'site': Site.objects.get_current(), 'confirmation': conf})
 
+            # TODO(stephenfin): Should this be surrounded by a try-except?
             send_mail(subject, message, settings.DEFAULT_FROM_EMAIL,
                       [conf.email])
 
@@ -149,10 +151,12 @@ def link(request):
 
             context['confirmation'] = conf
 
+            subject = 'Patchwork email address confirmation',
+            message = render_to_string('patchwork/mails/user-link.txt',
+                                       context, request=request)
             try:
-                send_mail('Patchwork email address confirmation',
-                          render_to_string('patchwork/user-link.mail',
-                                           context, request=request),
+                send_mail(subject,
+                          message,
                           settings.DEFAULT_FROM_EMAIL,
                           [form.cleaned_data['email']])
             except smtplib.SMTPException:
-- 
2.17.1



More information about the Patchwork mailing list