Skip to content
Snippets Groups Projects
Commit ff59a5d7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

formatting of email added

parent 86e61c84
No related branches found
No related tags found
1 merge request!231Resolve "auto-import of subject data"
...@@ -76,6 +76,7 @@ CRON_CLASSES = [ ...@@ -76,6 +76,7 @@ CRON_CLASSES = [
'web.views.kit.KitRequestEmailSendJob', 'web.views.kit.KitRequestEmailSendJob',
'web.redcap_connector.RedCapRefreshJob', 'web.redcap_connector.RedCapRefreshJob',
'web.views.voucher.ExpireVouchersJob', 'web.views.voucher.ExpireVouchersJob',
'web.importer.importer_cron_job.ImporterCronJob'
] ]
# Password validation # Password validation
......
...@@ -65,8 +65,17 @@ class Importer(object): ...@@ -65,8 +65,17 @@ class Importer(object):
self.added_count += 1 self.added_count += 1
def get_summary(self): def get_summary(self):
return "<p>Number of entries: <b>" + str(len(self.study_subjects)) + "</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 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 successfully merged entries: <b>" + str(self.merged_count) + "</b></p>"
"<p>Number of problematic entries: <b>" + str(self.problematic_count) + "</b></p>" + \ style = ''
"<p>Number of raised warnings: <b>" + str(self.warning_count) + "</b></p>" 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
...@@ -26,24 +26,28 @@ class ImporterCronJob(CronJobBase): ...@@ -26,24 +26,28 @@ class ImporterCronJob(CronJobBase):
recipients = getattr(settings, "DEFAULT_FROM_EMAIL", None) recipients = getattr(settings, "DEFAULT_FROM_EMAIL", None)
filename = getattr(settings, "DAILY_IMPORT_FILE", None) filename = getattr(settings, "DAILY_IMPORT_FILE", None)
if filename is None: if filename is None:
logger.info("Importing subjects skipped. File not defined ")
return "import file not defined" return "import file not defined"
logger.info("Importing subjects from file: " + filename)
if not os.path.isfile(filename): if not os.path.isfile(filename):
EmailSender().send_email(title, 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) recipients)
return "import file not found"
try: try:
importer = Importer(settings.DAILY_IMPORT_FILE, CsvSubjectImportReader()) importer = Importer(settings.DAILY_IMPORT_FILE, CsvSubjectImportReader())
importer.execute() importer.execute()
body = importer.get_summary() body = importer.get_summary()
EmailSender().send_email(title, 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) recipients)
return "import is successful" return "import is successful"
except: except:
tb = traceback.format_exc() tb = traceback.format_exc()
EmailSender().send_email(title, 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) recipients)
return "import crashed" return "import crashed"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment