From 28d8b239563ae4dcc18e7648136a39e0368a9092 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 13 Jun 2017 18:04:35 +0200
Subject: [PATCH] formatting of the email improved

---
 smash/web/views/kit.py | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/smash/web/views/kit.py b/smash/web/views/kit.py
index 7ade6ba5..aaa91741 100644
--- a/smash/web/views/kit.py
+++ b/smash/web/views/kit.py
@@ -74,20 +74,30 @@ def kit_requests_send_mail(request, start_date, end_date=None):
         end_date_str = data["end_date"].strftime('%Y-%m-%d')
     title = "Kits required between " + data["start_date"].strftime('%Y-%m-%d') + " and " + end_date_str
 
+    cell_style = "padding: 8px; line-height: 1.42857143; vertical-align: top; " \
+                 "font-size: 14px; font-family: 'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif;"
+
     email_body = "<h1>" + title + "</h1>"
-    email_body += "<table><thead><tr><th>Date</th><th>Kits</th><th>Location</th><th>Person responsible</th></tr></thead>"
+    email_body += '<table style="border: 1px solid #f4f4f4;border-spacing: 0;border-collapse: collapse;">' \
+                  '<thead><tr><th>Date</th><th>Kits</th><th>Location</th><th>Person responsible</th></tr></thead>'
     email_body += "<tbody>"
+
+    even = True
     for appointment in data["appointments"]:
-        email_body += "<tr>"
-        email_body += "<td>" + appointment.datetime_when.strftime('%Y-%m-%d %H:%M') + "</td>"
-        email_body += "<td>"
+        row_style = ""
+        even = not even
+        if even:
+            row_style = ' background-color: #f9f9f9;'
+        email_body += "<tr style='" + row_style + "'>"
+        email_body += "<td style='" + cell_style + "'>" + appointment.datetime_when.strftime('%Y-%m-%d %H:%M') + "</td>"
+        email_body += "<td style='" + cell_style + "'>"
         for type in appointment.appointment_types.all():
             for item in type.required_equipment.all():
                 if item.disposable:
                     email_body += item.name + ", "
         email_body += "</td>"
-        email_body += "<td>" + str(appointment.location) + "</td>"
-        email_body += "<td>" + str(appointment.worker_assigned) + "</td>"
+        email_body += "<td style='" + cell_style + "'>" + str(appointment.location) + "</td>"
+        email_body += "<td style='" + cell_style + "'>" + str(appointment.worker_assigned) + "</td>"
         email_body += "</tr>"
     email_body += "</tbody></table>"
     recipients = ConfigurationItem.objects.get(type=KIT_RECIPIENT_EMAIL_CONFIGURATION_TYPE).value
@@ -96,6 +106,7 @@ def kit_requests_send_mail(request, start_date, end_date=None):
     if sender is not None:
         cc_recipients.append(sender)
     try:
+        print email_body
         EmailSender().send_email(title, email_body, recipients, cc_recipients)
         messages.add_message(request, messages.SUCCESS, 'Mail sent')
     except:
-- 
GitLab