Skip to content
Snippets Groups Projects
Commit a224eecb authored by Carlos Vega's avatar Carlos Vega
Browse files

remove global variable, remove repeated code

parent 4718e7e4
No related branches found
No related tags found
1 merge request!349fixes #436 while keeping the constants that are relied on by many parts of the...
Pipeline #45899 passed
...@@ -19,9 +19,6 @@ DATE_FORMAT_SHORT = "%d.%m.%Y" ...@@ -19,9 +19,6 @@ DATE_FORMAT_SHORT = "%d.%m.%Y"
DATE_FORMAT_TIME = "%H:%M" DATE_FORMAT_TIME = "%H:%M"
now = datetime.datetime.now()
def date_format_encoding(): def date_format_encoding():
return locale.getlocale(locale.LC_TIME)[1] or locale.getpreferredencoding() return locale.getlocale(locale.LC_TIME)[1] or locale.getpreferredencoding()
...@@ -40,7 +37,7 @@ def get_formatted_time(time_format): ...@@ -40,7 +37,7 @@ def get_formatted_time(time_format):
# Was: # Was:
# return now.strftime(time_format).decode(date_format_encoding()) # return now.strftime(time_format).decode(date_format_encoding())
# Is: # Is:
return now.strftime(time_format) # /--> return datetime.datetime.now().strftime(time_format) # /-->
def date_to_str(date, format): def date_to_str(date, format):
...@@ -53,127 +50,13 @@ def date_to_str(date, format): ...@@ -53,127 +50,13 @@ def date_to_str(date, format):
else: else:
return "" return ""
class MailTemplate(models.Model): class MailTemplate(models.Model):
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", "")
]
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", ""),
]
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)),
]
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"),
]
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", ''),
]
@classmethod @classmethod
def update_tags(cls): def update_tags(cls):
"""This solves the problem of showing the tags with current times on the mail template """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. 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 = [ cls.MAILS_TEMPLATE_GENERIC_TAGS = [
("##DATE_FULL##", "Current date when the mail will be generated (long format)", ("##DATE_FULL##", "Current date when the mail will be generated (long format)",
get_formatted_time(DATE_FORMAT_FULL)), get_formatted_time(DATE_FORMAT_FULL)),
...@@ -548,3 +431,6 @@ class MailTemplate(models.Model): ...@@ -548,3 +431,6 @@ class MailTemplate(models.Model):
"##C_HOURS##": str(voucher.hours), "##C_HOURS##": str(voucher.hours),
} }
return {} return {}
MailTemplate.update_tags()
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