2020-06-04 20:37:28 -06:00
|
|
|
from flask_mail import Message
|
2020-06-29 16:41:42 -04:00
|
|
|
from jinja2 import Environment, FileSystemLoader
|
2020-06-04 00:35:59 -06:00
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
from crc import app, mail
|
2020-06-09 22:57:56 -06:00
|
|
|
from crc.services.email_service import EmailService
|
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
# Jinja environment definition, used to render mail templates
|
|
|
|
template_dir = app.root_path + '/static/templates/mails'
|
|
|
|
env = Environment(loader=FileSystemLoader(template_dir))
|
|
|
|
|
2020-06-04 00:35:59 -06:00
|
|
|
|
2020-06-08 14:15:56 -04:00
|
|
|
def send_test_email(sender, recipients):
|
|
|
|
try:
|
|
|
|
msg = Message('Research Ramp-up Plan test',
|
2020-06-29 16:41:42 -04:00
|
|
|
sender=sender,
|
|
|
|
recipients=recipients,
|
|
|
|
bcc=['rrt_emails@googlegroups.com'])
|
2020-06-08 14:15:56 -04:00
|
|
|
template = env.get_template('ramp_up_approval_request_first_review.txt')
|
|
|
|
template_vars = {'primary_investigator': "test"}
|
|
|
|
msg.body = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_approval_request_first_review.html')
|
|
|
|
msg.html = template.render(template_vars)
|
|
|
|
mail.send(msg)
|
|
|
|
except Exception as e:
|
|
|
|
return str(e)
|
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
|
2020-06-17 17:00:16 -06:00
|
|
|
def send_mail(subject, sender, recipients, content, content_html, study_id=None):
|
2020-06-25 16:18:42 -06:00
|
|
|
EmailService.add_email(subject=subject, sender=sender, recipients=recipients,
|
2020-06-29 16:41:42 -04:00
|
|
|
content=content, content_html=content_html, study_id=study_id)
|
|
|
|
|
2020-06-17 17:00:16 -06:00
|
|
|
|
2020-06-24 22:23:31 -06:00
|
|
|
def send_ramp_up_submission_email(sender, recipients, approver_1, approver_2=None):
|
2020-06-12 12:17:08 -06:00
|
|
|
subject = 'Research Ramp-up Plan Submitted'
|
|
|
|
|
|
|
|
template = env.get_template('ramp_up_submission.txt')
|
|
|
|
template_vars = {'approver_1': approver_1, 'approver_2': approver_2}
|
|
|
|
content = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_submission.html')
|
|
|
|
content_html = template.render(template_vars)
|
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
send_mail(subject, sender, recipients, content, content_html)
|
|
|
|
|
2020-06-12 12:17:08 -06:00
|
|
|
|
2020-06-24 22:23:31 -06:00
|
|
|
def send_ramp_up_approval_request_email(sender, recipients, primary_investigator):
|
2020-06-12 12:17:08 -06:00
|
|
|
subject = 'Research Ramp-up Plan Approval Request'
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-12 12:17:08 -06:00
|
|
|
template = env.get_template('ramp_up_approval_request.txt')
|
|
|
|
template_vars = {'primary_investigator': primary_investigator}
|
|
|
|
content = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_approval_request.html')
|
|
|
|
content_html = template.render(template_vars)
|
2020-06-09 22:57:56 -06:00
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
send_mail(subject, sender, recipients, content, content_html)
|
|
|
|
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-24 22:23:31 -06:00
|
|
|
def send_ramp_up_approval_request_first_review_email(sender, recipients, primary_investigator):
|
2020-06-12 12:17:08 -06:00
|
|
|
subject = 'Research Ramp-up Plan Approval Request'
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-12 12:17:08 -06:00
|
|
|
template = env.get_template('ramp_up_approval_request_first_review.txt')
|
|
|
|
template_vars = {'primary_investigator': primary_investigator}
|
|
|
|
content = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_approval_request_first_review.html')
|
|
|
|
content_html = template.render(template_vars)
|
2020-06-09 22:57:56 -06:00
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
send_mail(subject, sender, recipients, content, content_html)
|
|
|
|
|
2020-06-04 00:35:59 -06:00
|
|
|
|
2020-06-24 22:23:31 -06:00
|
|
|
def send_ramp_up_approved_email(sender, recipients, approver_1, approver_2=None):
|
2020-06-12 12:17:08 -06:00
|
|
|
subject = 'Research Ramp-up Plan Approved'
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-12 12:17:08 -06:00
|
|
|
template = env.get_template('ramp_up_approved.txt')
|
|
|
|
template_vars = {'approver_1': approver_1, 'approver_2': approver_2}
|
|
|
|
content = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_approved.html')
|
|
|
|
content_html = template.render(template_vars)
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
send_mail(subject, sender, recipients, content, content_html)
|
|
|
|
|
2020-06-04 00:35:59 -06:00
|
|
|
|
2020-06-24 22:23:31 -06:00
|
|
|
def send_ramp_up_denied_email(sender, recipients, approver):
|
2020-06-12 12:17:08 -06:00
|
|
|
subject = 'Research Ramp-up Plan Denied'
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-12 12:17:08 -06:00
|
|
|
template = env.get_template('ramp_up_denied.txt')
|
|
|
|
template_vars = {'approver': approver}
|
|
|
|
content = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_denied.html')
|
|
|
|
content_html = template.render(template_vars)
|
2020-06-04 20:37:28 -06:00
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
send_mail(subject, sender, recipients, content, content_html)
|
|
|
|
|
2020-06-05 12:08:31 -06:00
|
|
|
|
2020-06-24 22:23:31 -06:00
|
|
|
def send_ramp_up_denied_email_to_approver(sender, recipients, primary_investigator, approver_2):
|
2020-06-12 12:17:08 -06:00
|
|
|
subject = 'Research Ramp-up Plan Denied'
|
2020-06-05 12:08:31 -06:00
|
|
|
|
2020-06-12 12:17:08 -06:00
|
|
|
template = env.get_template('ramp_up_denied_first_approver.txt')
|
|
|
|
template_vars = {'primary_investigator': primary_investigator, 'approver_2': approver_2}
|
|
|
|
content = template.render(template_vars)
|
|
|
|
template = env.get_template('ramp_up_denied_first_approver.html')
|
|
|
|
content_html = template.render(template_vars)
|
2020-06-05 12:08:31 -06:00
|
|
|
|
2020-06-29 16:41:42 -04:00
|
|
|
send_mail(subject, sender, recipients, content, content_html)
|