Commit 6c7c8686 authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Update logic for email sending

parent b7496738
......@@ -803,20 +803,23 @@ class ProfessorMessage(models.Model):
bcc_es = [u.email for u in self.users.all() if u.is_active and re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", u.email) and u.preferred_language == 'es']
bcc_pt_br = [u.email for u in self.users.all() if u.is_active and re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", u.email) and u.preferred_language == 'pt-br']
subject_en = Template(et.subject).render(Context({'subject': self.subject_en}))
message_en = Template(et.template).render(Context({'message': self.message_en}))
if self.subject_en and self.message_en:
self.send_emails(bcc_en, message_en, subject_en, email_batch_size)
subject_es = Template(et.subject).render(Context({'subject': self.subject_es}))
message_es = Template(et.template).render(Context({'message': self.message_es}))
if self.subject_es and self.message_es:
self.send_emails(bcc_es, message_es, subject_es, email_batch_size)
subject_pt_br = Template(et.subject).render(Context({'subject': self.subject_pt_br}))
message_pt_br = Template(et.template).render(Context({'message': self.message_pt_br}))
if self.subject_pt_br and self.message_pt_br:
self.send_emails(bcc_pt_br, message_pt_br, subject_pt_br, email_batch_size)
subject_en = self.subject_en or self.subject
message_en = self.message_en or self.message
subject_en = Template(et.subject).render(Context({'subject': subject_en}))
message_en = Template(et.template).render(Context({'message': message_en}))
self.send_emails(bcc_en, message_en, subject_en, email_batch_size)
subject_es = self.subject_es or self.subject
message_es = self.message_es or self.message
subject_es = Template(et.subject).render(Context({'subject': subject_es}))
message_es = Template(et.template).render(Context({'message': message_es}))
self.send_emails(bcc_es, message_es, subject_es, email_batch_size)
subject_pt_br = self.subject_pt_br or self.subject
message_pt_br = self.message_pt_br or self.message
subject_pt_br = Template(et.subject).render(Context({'subject': subject_pt_br}))
message_pt_br = Template(et.template).render(Context({'message': message_pt_br}))
self.send_emails(bcc_pt_br, message_pt_br, subject_pt_br, email_batch_size)
else:
bcc = [u.email for u in self.users.all() if u.is_active and re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", u.email)]
subject = Template(et.subject).render(Context({'subject': self.subject}))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment