From ff59a5d756d6a3ab5f63f13bcc740f3801f6e87e Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Sun, 5 Apr 2020 20:54:02 +0200
Subject: [PATCH] formatting of email added

---
 smash/smash/settings.py                 |  1 +
 smash/web/importer/importer.py          | 19 ++++++++++++++-----
 smash/web/importer/importer_cron_job.py | 10 +++++++---
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/smash/smash/settings.py b/smash/smash/settings.py
index c11fe16a..14f7a7ff 100644
--- a/smash/smash/settings.py
+++ b/smash/smash/settings.py
@@ -76,6 +76,7 @@ CRON_CLASSES = [
     'web.views.kit.KitRequestEmailSendJob',
     'web.redcap_connector.RedCapRefreshJob',
     'web.views.voucher.ExpireVouchersJob',
+    'web.importer.importer_cron_job.ImporterCronJob'
 ]
 
 # Password validation
diff --git a/smash/web/importer/importer.py b/smash/web/importer/importer.py
index ab4427fd..1e9b377e 100644
--- a/smash/web/importer/importer.py
+++ b/smash/web/importer/importer.py
@@ -65,8 +65,17 @@ class Importer(object):
             self.added_count += 1
 
     def get_summary(self):
-        return "<p>Number of entries: <b>" + str(len(self.study_subjects)) + "</b></p>" + \
-               "<p>Number of successfully added entries: <b>" + str(self.added_count) + "</b></p>" + \
-               "<p>Number of successfully merged entries: <b>" + str(self.merged_count) + "</b></p>" + \
-               "<p>Number of problematic entries: <b>" + str(self.problematic_count) + "</b></p>" + \
-               "<p>Number of raised warnings: <b>" + str(self.warning_count) + "</b></p>"
+        result = "<p>Number of entries: <b>" + str(len(self.study_subjects)) + "</b></p>" + \
+                 "<p>Number of successfully added entries: <b>" + str(self.added_count) + "</b></p>" + \
+                 "<p>Number of successfully merged entries: <b>" + str(self.merged_count) + "</b></p>"
+        style = ''
+        if self.problematic_count > 0:
+            style = ' color="red" '
+        result += "<p><font " + style + ">Number of problematic entries: <b>" + str(
+            self.problematic_count) + "</b></font></p>"
+        style = ''
+        if self.warning_count > 0:
+            style = ' color="brown" '
+        result += "<p><font " + style + ">Number of raised warnings: <b>" + str(self.warning_count) + "</b></font></p>"
+
+        return result
diff --git a/smash/web/importer/importer_cron_job.py b/smash/web/importer/importer_cron_job.py
index 3a9b0d97..18ea4727 100644
--- a/smash/web/importer/importer_cron_job.py
+++ b/smash/web/importer/importer_cron_job.py
@@ -26,24 +26,28 @@ class ImporterCronJob(CronJobBase):
         recipients = getattr(settings, "DEFAULT_FROM_EMAIL", None)
 
         filename = getattr(settings, "DAILY_IMPORT_FILE", None)
+
         if filename is None:
+            logger.info("Importing subjects skipped. File not defined ")
             return "import file not defined"
+        logger.info("Importing subjects from file: " + filename)
         if not os.path.isfile(filename):
             EmailSender().send_email(title,
-                                     "<h1>File with imported data is not available in the system: " + filename + "</h1>",
+                                     "<h3><font color='red'>File with imported data is not available in the system: " + filename + "</font></h3>",
                                      recipients)
+            return "import file not found"
         try:
             importer = Importer(settings.DAILY_IMPORT_FILE, CsvSubjectImportReader())
             importer.execute()
             body = importer.get_summary()
             EmailSender().send_email(title,
-                                     "<h1>Data was successfully imported from file: " + filename + "</h1>" + body,
+                                     "<h3>Data was successfully imported from file: " + filename + "</h3>" + body,
                                      recipients)
             return "import is successful"
 
         except:
             tb = traceback.format_exc()
             EmailSender().send_email(title,
-                                     "<h1>There was a problem with importing data from file: " + filename + "</h1>" + tb,
+                                     "<h3><font color='red'>There was a problem with importing data from file: " + filename + "</font></h3><pre>" + tb + "</pre>",
                                      recipients)
             return "import crashed"
-- 
GitLab