diff --git a/smash/web/models/mail_template.py b/smash/web/models/mail_template.py index 3d18549f13dd386c61ade1d9353fd3f65473c789..604a064b26ee2e2ecf85d9a32f1b778b3b95bade 100644 --- a/smash/web/models/mail_template.py +++ b/smash/web/models/mail_template.py @@ -13,7 +13,7 @@ from ..models import Appointment, Visit, StudySubject, Worker, Voucher DATE_FORMAT_FULL = "%A %d %B %Y" -DATETIME_FORMAT = "%A %d %B %Y, %H:%m" +DATETIME_FORMAT = "%A %d %B %Y, %H:%M" DATE_FORMAT_SHORT = "%d.%m.%Y" @@ -59,7 +59,7 @@ class MailTemplate(models.Model): ("##DATE_FULL##", "Current date when the mail will be generated (long format)", get_formatted_time(DATE_FORMAT_FULL)), ("##DATE_SHORT##", "Current date when the mail will be generated (short format)", - now.strftime(DATE_FORMAT_SHORT)), + get_formatted_time(DATE_FORMAT_SHORT)), ("##WORKER##", "The full name of the currently logged in user", ""), ("##WORKER_EMAIL##", "Email address of the currently logged in user", "") ] @@ -167,6 +167,125 @@ class MailTemplate(models.Model): ("##C_HOURS##", "Hours", ''), ] + @classmethod + def update_tags(cls): + """This solves the problem of showing the tags with current times on the mail template + view while keeping the constant structure that is accessed in many parts of the code. + """ + global now + now = datetime.datetime.now() + cls.MAILS_TEMPLATE_GENERIC_TAGS = [ + ("##DATE_FULL##", "Current date when the mail will be generated (long format)", + get_formatted_time(DATE_FORMAT_FULL)), + ("##DATE_SHORT##", "Current date when the mail will be generated (short format)", + get_formatted_time(DATE_FORMAT_SHORT)), + ("##WORKER##", "The full name of the currently logged in user", ""), + ("##WORKER_EMAIL##", "Email address of the currently logged in user", "") + ] + + cls.MAILS_TEMPLATE_SUBJECT_TAGS = [ + ("##S_FULL_NAME##", "Subject's full name", "first_name last_name"), + ("##S_FIRST_NAME##", "Subject's first name", ""), + ("##S_LAST_NAME##", "Subject's last name", ""), + ("##S_ADDRESS##", "Subject's address", "street name and number"), + ("##S_CITY##", "Subject's city of residence", ""), + ("##S_POST_CODE##", "Subject's post code of residence", ""), + ("##S_COUNTRY##", "Subject's country of residence", ""), + ("##S_SEX##", "Subject's gender", "Male/Female"), + ("##S_TYPE##", "Subject's type", "CONTROL/PATIENT"), + ("##S_DATE_BORN##", "Subject's date of birth", get_formatted_time(DATE_FORMAT_SHORT)), + + ("##S_EMAIL##", "Subject's email address", ""), + ("##S_PHONE_NUMBER##", "Subject's phone number", ""), + ("##S_PHONE_NUMBER_2##", "Subject's second phone number", ""), + ("##S_PHONE_NUMBER_3##", "Subject's third phone number", ""), + ("##S_MAIL_LANGUAGE##", "Subject's preferred language for written communication", ""), + ("##S_KNOWN_LANGUAGES##", "List of languages known by the subject", "comma separated"), + + ("##S_SCREENING_NUMBER##", "Subject's screening number", ""), + ("##S_DIAGNOSIS##", "Subject's diagnosis", ""), + ("##S_DIAGNOSIS_YEAR##", "Subject's year of diagnosis", ""), + ("##S_MPOWER_ID##", "Subject's mPower identifier", ""), + ("##S_ND_NUMBER##", "Subject's ND number", ""), + ("##S_DATE_ADDED##", "Subject's date of creation", get_formatted_time(DATE_FORMAT_SHORT)), + + ("##S_VIRUS_1_SAMPLE_COLLECTION_DATE##", "Virus test collection date in visit 1", + get_formatted_time(DATE_FORMAT_SHORT)), + ("##S_VIRUS_2_SAMPLE_COLLECTION_DATE##", "Virus test collection date in visit 2", + get_formatted_time(DATE_FORMAT_SHORT)), + ("##S_VIRUS_3_SAMPLE_COLLECTION_DATE##", "Virus test collection date in visit 3", + get_formatted_time(DATE_FORMAT_SHORT)), + ("##S_VIRUS_4_SAMPLE_COLLECTION_DATE##", "Virus test collection date in visit 4", + get_formatted_time(DATE_FORMAT_SHORT)), + ("##S_VIRUS_5_SAMPLE_COLLECTION_DATE##", "Virus test collection date in visit 5", + get_formatted_time(DATE_FORMAT_SHORT)), + + ("##S_VIRUS_1_RESULT##", "Virus test results in visit 1", "Positive"), + ("##S_VIRUS_2_RESULT##", "Virus test results in visit 2", "Negative"), + ("##S_VIRUS_3_RESULT##", "Virus test results in visit 3", "Inconclusive"), + ("##S_VIRUS_4_RESULT##", "Virus test results in visit 4", ""), + ("##S_VIRUS_5_RESULT##", "Virus test results in visit 5", ""), + + ("##S_VIRUS_1_IGA_STATUS##", "IgA Status in visit 1", "Positive"), + ("##S_VIRUS_2_IGA_STATUS##", "IgA Status in visit 2", "Negative"), + ("##S_VIRUS_3_IGA_STATUS##", "IgA Status in visit 3", "Borderline"), + ("##S_VIRUS_4_IGA_STATUS##", "IgA Status in visit 4", ""), + ("##S_VIRUS_5_IGA_STATUS##", "IgA Status in visit 5", ""), + + ("##S_VIRUS_1_IGG_STATUS##", "IgG Status in visit 1", "Positive"), + ("##S_VIRUS_2_IGG_STATUS##", "IgG Status in visit 2", "Negative"), + ("##S_VIRUS_3_IGG_STATUS##", "IgG Status in visit 3", "Borderline"), + ("##S_VIRUS_4_IGG_STATUS##", "IgG Status in visit 4", ""), + ("##S_VIRUS_5_IGG_STATUS##", "IgG Status in visit 5", ""), + + ("##S_HEALTH_PARTNER_NAME##", "Name of the health partner", ""), + ("##S_HEALTH_PARTNER_ADDRESS##", "Address of the health partner", ""), + ("##S_HEALTH_PARTNER_ZIP_CODE##", "Zip code of the health partner", ""), + ("##S_HEALTH_PARTNER_CITY##", "City of the health partner", ""), + + ] + + cls.MAILS_TEMPLATE_VISIT_TAGS = [ + ("##V_DATE_START_FULL##", "Visit's start date", get_formatted_time(DATETIME_FORMAT)), + ("##V_DATE_START_SHORT##", "Visit's start date", get_formatted_time(DATE_FORMAT_SHORT)), + ("##V_DATE_ENDS_FULL##", "Visit's end date", get_formatted_time(DATETIME_FORMAT)), + ("##V_DATE_ENDS_SHORT##", "Visit's end date", get_formatted_time(DATE_FORMAT_SHORT)), + ] + + cls.MAILS_TEMPLATE_APPOINTMENT_TAGS = [ + ("##A_DATE_FULL##", "Appointment's date and time", get_formatted_time(DATETIME_FORMAT)), + ("##A_DATE_SHORT##", "Appointment's date", get_formatted_time(DATE_FORMAT_SHORT)), + ("##A_TIME##", "Appointment's time", get_formatted_time(DATE_FORMAT_TIME)), + ("##A_FLYING_TEAM##", "Appointment's flying team location", ""), + ("##A_LOCATION##", "Appointment's location", "value can be 'Flying Team'"), + ("##A_LOCATION_OR_FLYINGTEAM##", "Appointment's real location", + "if flying team then returns flying team exact location, otherwise returns location name"), + ("##A_STATUS##", "Appointment's status", ""), + ("##A_WORKER##", "Worker conducting the assessment", "first_name last_name"), + ("##A_WORKER_PHONE##", "Phone number of the worker conducting the assessment", ""), + ("##A_WORKER_EMAIL##", "Email address of the worker conducting the assessment", ""), + ("##A_ROOM##", "Appointment's room", 'room_number address city'), + ("##A_LENGTH##", "Appointment's duration", 'integer, value in minutes'), + ("##A_TYPES##", "Appointment's types", "comma separated"), + ] + + cls.MAILS_TEMPLATE_VOUCHER_TAGS = [ + ("##C_NUMBER##", "Number", ''), + ("##C_PATIENT_NAME##", "Voucher Partner name", ''), + ("##C_VOUCHER_TYPE##", "Voucher type", ''), + + ("##C_ISSUE_DATE_SHORT##", "Issue date", get_formatted_time(DATE_FORMAT_SHORT)), + ("##C_EXPIRY_START_SHORT##", "Expiry date", get_formatted_time(DATE_FORMAT_SHORT)), + + ("##C_PARTNER_NAME##", "Voucher Partner name", ''), + ("##C_PARTNER_ADDRESS##", "Voucher Partner address", ''), + ("##C_PARTNER_CITY##", "Voucher Partner city", ''), + ("##C_PARTNER_POSTAL_CODE##", "Voucher Partner postal code", ''), + ("##C_PARTNER_COUNTRY##", "Voucher Partner country", ''), + ("##C_PARTNER_PHONE##", "Voucher Partner phone", ''), + ("##C_HOURS##", "Hours", ''), + ] + name = models.CharField(max_length=255) context = models.CharField(max_length=1, choices=MAIL_TEMPLATE_CONTEXT_CHOICES) language = models.ForeignKey("web.Language", on_delete=models.CASCADE, blank=True, null=True) diff --git a/smash/web/views/mails.py b/smash/web/views/mails.py index 2e13b20fa54a7cb90a0f15eea357072befb709e2..0f5a76bda5d62048f944701f53231ebc3a0ab828 100644 --- a/smash/web/views/mails.py +++ b/smash/web/views/mails.py @@ -39,6 +39,7 @@ class MailTemplatesListView(ListView, WrappedView): def get_context_data(self, *args, **kwargs): context = super(MailTemplatesListView, self).get_context_data() + MailTemplate.update_tags() context['explanations'] = {"generic": MailTemplate.MAILS_TEMPLATE_GENERIC_TAGS, "subject": MailTemplate.MAILS_TEMPLATE_SUBJECT_TAGS, "visit": MailTemplate.MAILS_TEMPLATE_VISIT_TAGS,