Beispiel #1
0
def notify_instructors_of_changes(course, approval, previous_approvals):
    template = _get_email_template(course=course, template_type='notify_instructor_of_changes')
    if not template:
        return
    for previous_approval in previous_approvals:
        instructor = next((i for i in course['instructors'] if i['uid'] == previous_approval.approved_by_uid), None)
        if not instructor:
            continue
        message = interpolate_content(
            templated_string=template.message,
            course=course,
            recipient_name=instructor['name'],
            previous_publish_type_name=NAMES_PER_PUBLISH_TYPE.get(previous_approvals[-1].publish_type),
            previous_recording_type_name=NAMES_PER_RECORDING_TYPE.get(previous_approvals[-1].recording_type),
            publish_type_name=NAMES_PER_PUBLISH_TYPE.get(approval.publish_type),
            recording_type_name=NAMES_PER_RECORDING_TYPE.get(approval.recording_type),
        )
        subject_line = interpolate_content(
            templated_string=template.subject_line,
            course=course,
            recipient_name=instructor['name'],
        )
        QueuedEmail.create(
            message=message,
            recipient=instructor,
            section_id=course['sectionId'],
            subject_line=subject_line,
            template_type='notify_instructor_of_changes',
            term_id=course['termId'],
        )
    return True
Beispiel #2
0
def notify_instructors_recordings_scheduled(course, scheduled):
    template_type = 'recordings_scheduled'
    email_template = EmailTemplate.get_template_by_type(template_type)
    if email_template:
        publish_type_name = NAMES_PER_PUBLISH_TYPE[scheduled.publish_type]
        recording_type_name = NAMES_PER_RECORDING_TYPE[scheduled.recording_type]
        for instructor in course['instructors']:
            message = interpolate_content(
                templated_string=email_template.message,
                course=course,
                recipient_name=instructor['name'],
                publish_type_name=publish_type_name,
                recording_type_name=recording_type_name,
            )
            subject_line = interpolate_content(
                templated_string=email_template.subject_line,
                course=course,
                recipient_name=instructor['name'],
            )
            QueuedEmail.create(
                message=message,
                subject_line=subject_line,
                recipient=instructor,
                section_id=course['sectionId'],
                template_type=email_template.template_type,
                term_id=course['termId'],
            )
    else:
        send_system_error_email(f"""
            No email template of type {template_type} is available.
            {course['label']} instructors were NOT notified of scheduled: {scheduled}.
        """)
Beispiel #3
0
def notify_instructor_waiting_for_approval(course, instructor,
                                           pending_instructors):
    template = _get_email_template(course=course,
                                   template_type='waiting_for_approval')
    if not template:
        return
    message = interpolate_content(
        templated_string=template.message,
        course=course,
        recipient_name=instructor['name'],
        pending_instructors=pending_instructors,
    )
    subject_line = interpolate_content(
        templated_string=template.subject_line,
        course=course,
        recipient_name=instructor['name'],
    )
    return QueuedEmail.create(
        message=message,
        recipient=instructor,
        section_id=course['sectionId'],
        subject_line=subject_line,
        template_type='waiting_for_approval',
        term_id=course['termId'],
    )
Beispiel #4
0
 def interpolate(self, course):
     template = _get_email_template(course=course, template_type=self.template_type)
     if template:
         self.subject_line = interpolate_content(
             course=course,
             templated_string=template.subject_line,
             recipient_name=self.recipient['name'],
         )
         self.message = interpolate_content(
             course=course,
             templated_string=template.message,
             recipient_name=self.recipient['name'],
         )
         db.session.add(self)
         std_commit()
         # Return True only if all required data has been set.
         return self.is_interpolated
Beispiel #5
0
 def _get_interpolate_content(template):
     scheduled = course.get('scheduled', {})
     return interpolate_content(
         course=course,
         publish_type_name=scheduled.get('publishTypeName'),
         recipient_name=recipient['name'],
         recording_type_name=scheduled.get('recordingTypeName'),
         templated_string=template,
     )
 def _get_interpolated_content(templated_string):
     return interpolate_content(
         course=course,
         pending_instructors=course['instructors'],
         previous_publish_type_name=NAMES_PER_PUBLISH_TYPE[publish_types[0]],
         previous_recording_type_name=NAMES_PER_RECORDING_TYPE[recording_types[0]],
         publish_type_name=NAMES_PER_PUBLISH_TYPE[publish_types[1]],
         recording_type_name=NAMES_PER_RECORDING_TYPE[recording_types[1]],
         recipient_name=current_user.name,
         templated_string=templated_string,
     )
 def test_interpolate_email_content(self):
     instructor = get_calnet_user_for_uid(app, '10005')
     course = SisSection.get_course(app.config['CURRENT_TERM_ID'], '50003')
     interpolated = interpolate_content(
         course=course,
         recipient_name=instructor['name'],
         templated_string=_get_email_template(),
     )
     actual = _normalize(interpolated)
     expected = _normalize(_get_expected_email())
     assert expected == actual