diff --git a/app/logic/emailHandler.py b/app/logic/emailHandler.py index 1de8ef49..d5fbf0e6 100644 --- a/app/logic/emailHandler.py +++ b/app/logic/emailHandler.py @@ -347,11 +347,11 @@ def checkRecipient(self, studentEmailPurpose=False, emailPurpose=False, secondar # Depending on the parameter 'sendTo', this method will send the email either to the Primary, Secondary, or the Student def sendEmail(self, template, sendTo): + formTemplate = template.body formTemplate = self.replaceText(formTemplate) if sendTo == "student": - message = Message(template.subject, - recipients=[self.studentEmail]) + message = Message(template.subject, recipients = [self.studentEmail]) recipient = 'Student' elif sendTo == "secondary": if self.term.isBreak: @@ -363,8 +363,7 @@ def sendEmail(self, template, sendTo): recipients=supervisorEmails) recipient = 'Secondary Supervisor' else: - message = Message(template.subject, - recipients=[self.supervisorEmail, self.primaryEmail]) + message = Message(template.subject, recipients=[self.supervisorEmail, self.primaryEmail]) recipient = 'Primary Supervisor' elif sendTo == "Labor Office": message = Message(template.subject, @@ -375,18 +374,18 @@ def sendEmail(self, template, sendTo): recipients=[self.supervisorEmail]) recipient = 'Primary Supervisor' elif sendTo == "admin": - message = Message(template.subject, - recipients=[self.adminEmail]) + message = Message(template.subject, recipients=[self.adminEmail]) recipient = 'Admin' message.html = formTemplate - + newEmailTracker = EmailTracker.create( formID = self.laborStatusForm.laborStatusFormID, date = datetime.today().strftime('%Y-%m-%d'), recipient = recipient, - subject = template.subject + template = template.emailTemplateID, + recipientEmails = ",".join(message.recipients), + body = formTemplate, ) - self.send(message) # This method is responsible for replacing the keyword form the templates in the database with the data in the laborStatusForm diff --git a/app/models/emailTracker.py b/app/models/emailTracker.py index ff0495eb..a3fb42b8 100644 --- a/app/models/emailTracker.py +++ b/app/models/emailTracker.py @@ -1,9 +1,14 @@ from app.models import * from app.models.laborStatusForm import LaborStatusForm +from app.models.emailTemplate import EmailTemplate class EmailTracker(baseModel): emailTrackerID = PrimaryKeyField() - formID = ForeignKeyField(LaborStatusForm, on_delete="cascade") # foreign key to lsf + formID = ForeignKeyField(LaborStatusForm) # foreign key to lsf date = DateField() recipient = CharField() - subject = CharField() + template = ForeignKeyField(EmailTemplate) # foreign key to email template + recipientEmails = TextField() + body = TextField() + + diff --git a/database/data-scrub.sql b/database/data-scrub.sql index af3c3125..719cfb21 100644 --- a/database/data-scrub.sql +++ b/database/data-scrub.sql @@ -12,3 +12,7 @@ UPDATE laborstatusform set laborDepartmentNotes=CASE WHEN LENGTH(laborDepartment UPDATE notes set notesContents='Notes are not visible except in the production environment' UPDATE studentlaborevaluation SET attendance_comment=CASE WHEN LENGTH(attendance_comment)>0 THEN '' ELSE '' END, accountability_comment=CASE WHEN LENGTH(accountability_comment)>0 THEN '' ELSE '' END, teamwork_comment=CASE WHEN LENGTH(teamwork_comment)>0 THEN '' ELSE '' END, initiative_comment=CASE WHEN LENGTH(initiative_comment)>0 THEN '' ELSE '' END, respect_comment=CASE WHEN LENGTH(respect_comment)>0 THEN '' ELSE '' END, learning_comment=CASE WHEN LENGTH(learning_comment)>0 THEN '' ELSE '' END, jobSpecific_comment=CASE WHEN LENGTH(jobSpecific_comment)>0 THEN '' ELSE '' END, transcript_comment=CASE WHEN LENGTH(transcript_comment)>0 THEN '' ELSE '' END + +-- removes parts of the email tracker +UPDATE emailtracker set recipientEmails=CASE WHEN LENGTH(recipientEmails)>0 THEN '' ELSE '' END +UPDATE emailtracker set body=CASE WHEN LENGTH(body)>0 THEN '' ELSE '' END \ No newline at end of file diff --git a/database/demo_data.py b/database/demo_data.py index 0557c936..6c029e33 100644 --- a/database/demo_data.py +++ b/database/demo_data.py @@ -17,6 +17,7 @@ from app.models.laborStatusForm import LaborStatusForm from app.models.formHistory import FormHistory from app.models.notes import Notes +from app.models.emailTracker import EmailTracker print("Inserting data for demo and testing purposes") @@ -609,3 +610,17 @@ ] Notes.insert_many(notes).on_conflict_replace().execute() print(" * laborOfficeNotes added") + + +############################# +# Creates an emailTracker +############################# +EmailTracker.insert([{ + "emailTrackerID": 1000000, + "formID": 2, + "date": "2026-06-18", + "recipient": "Julius Fritz", + "template": 4, + "recipientEmails": "fritzj2@berea.edu", + "body": "super secret text that you cant read" + }]).on_conflict_replace().execute() \ No newline at end of file