diff --git a/smash/smash/settings.py b/smash/smash/settings.py index c11fe16accedc21a7dcdf46f168e4305be7ec5ea..14f7a7ff96dc662eadb5b2216029619d0f16cc28 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 ab4427fddeeef3cc1163f696c8ed5455392d48be..1e9b377e3da44042c3b8607181adab60c8e5d6a8 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 3a9b0d97aa73b25caddbb950cb1d13b8a6fad497..18ea4727e34af40a8bc2084799d07d6091dbe86e 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"