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}. """)
def _room_change_alert(self): template_type = 'room_change_no_longer_eligible' all_scheduled = list( filter( lambda s: template_type not in (s.alerts or []), Scheduled.get_all_scheduled(term_id=self.term_id), ), ) if all_scheduled: email_template = EmailTemplate.get_template_by_type(template_type) courses = SisSection.get_courses( term_id=self.term_id, section_ids=[s.section_id for s in all_scheduled], include_deleted=True, ) courses_per_section_id = dict( (course['sectionId'], course) for course in courses) for scheduled in all_scheduled: course = courses_per_section_id.get(scheduled.section_id) if course: if self._has_moved_to_ineligible_room( course, scheduled) or course['deletedAt']: if email_template: for instructor in course['instructors']: def _get_interpolate_content(template): return interpolate_content( course=course, publish_type_name=course.get( 'scheduled', {}).get('publishTypeName'), recipient_name=instructor['name'], recording_type_name=course.get( 'scheduled', {}).get('recordingTypeName'), templated_string=template, ) QueuedEmail.create( message=_get_interpolate_content( email_template.message), recipient=instructor, section_id=course['sectionId'], subject_line=_get_interpolate_content( email_template.subject_line), template_type=template_type, term_id=self.term_id, ) Scheduled.add_alert( scheduled_id=course['scheduled']['id'], template_type=template_type) else: send_system_error_email(f""" No '{template_type}' email template available. We are unable to notify {course['label']} instructors of room change. """) else: subject = f'Scheduled course has no SIS data (section_id={scheduled.section_id})' message = f'{subject}\n\nScheduled:<pre>{scheduled}</pre>' app.logger.error(message) send_system_error_email(message=message, subject=subject)
def _notify(self, course, template_type): email_template = EmailTemplate.get_template_by_type(template_type) if email_template: 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, ) recipient = get_admin_alert_recipient() QueuedEmail.create( message=_get_interpolate_content(email_template.message), recipient=recipient, section_id=course['sectionId'], subject_line=_get_interpolate_content( email_template.subject_line), template_type=template_type, term_id=self.term_id, ) Scheduled.add_alert(scheduled_id=course['scheduled']['id'], template_type=template_type) else: send_system_error_email(f""" No email template of type {template_type} is available. Diablo admin NOT notified in regard to course {course['label']}. """)
def send_course_related_email( course, recipients, template_type, term_id, ): template = EmailTemplate.get_template_by_type(template_type) if template: def _interpolate(templated_string): return interpolate_email_content( course=course, templated_string=templated_string, ) BConnected().send( message=_interpolate(template.message), recipients=recipients, section_id=course['sectionId'], subject_line=_interpolate(template.subject_line), template_type=template_type, term_id=term_id, ) return True else: send_system_error_email( f'Unable to send email of type {template_type} because no template is available.' ) return False
def _get_email_template(course, template_type): template = EmailTemplate.get_template_by_type(template_type) if not template: subject = f"No {template_type} email template found; failed to queue email for section_id {course['sectionId']}" send_system_error_email( message=f'{subject}\n\n<pre>{course}</pre>', subject=subject, ) return template
def _notify(course, template_type): email_template = EmailTemplate.get_template_by_type(template_type) BConnected().send( message=interpolate_email_content( templated_string=email_template.message, course=course, ), recipients=get_admin_alert_recipients(), subject_line=interpolate_email_content( templated_string=email_template.subject_line, course=course, ), )
def notify_instructors_of_approval( course, latest_approval, name_of_latest_approver, template_type, term_id, pending_instructors=None, notify_only_latest_instructor=False, previous_publish_type=None, previous_recording_type=None, ): template = EmailTemplate.get_template_by_type(template_type) if template: def _interpolate(templated_string): return interpolate_email_content( course=course, instructor_name=name_of_latest_approver, pending_instructors=pending_instructors, previous_publish_type_name=NAMES_PER_PUBLISH_TYPE.get( previous_publish_type), previous_recording_type_name=NAMES_PER_RECORDING_TYPE.get( previous_recording_type), publish_type_name=NAMES_PER_PUBLISH_TYPE.get( latest_approval.publish_type), recording_type_name=NAMES_PER_RECORDING_TYPE.get( latest_approval.recording_type), templated_string=templated_string, ) if notify_only_latest_instructor: recipients = [ next((i for i in course['instructors'] if i['uid'] == latest_approval.uid)) ] else: recipients = course['instructors'] BConnected().send( message=_interpolate(template.message), recipients=recipients, section_id=course['sectionId'], subject_line=_interpolate(template.subject_line), template_type=template_type, term_id=term_id, ) return True else: send_system_error_email( f'Unable to send email of type {template_type} because no template is available.' ) return False
def run(self): term_id = app.config['CURRENT_TERM_ID'] all_scheduled = Scheduled.get_all_scheduled(term_id=term_id) if all_scheduled: courses = SisSection.get_courses( term_id=term_id, section_ids=[s.section_id for s in all_scheduled]) courses_per_section_id = dict( (course['sectionId'], course) for course in courses) for scheduled in all_scheduled: course = courses_per_section_id[scheduled.section_id] if course: if scheduled.room_id != course['room']['id']: email_template = EmailTemplate.get_template_by_type( 'room_change_no_longer_eligible') for instructor in course['instructor']: BConnected().send( message=interpolate_email_content( templated_string=email_template.message, course=course, instructor_name=instructor['name'], recipient_name=instructor['name'], recording_type_name=scheduled. recording_type, ), recipients=course['instructors'], subject_line=interpolate_email_content( templated_string=email_template. subject_line, course=course, instructor_name=instructor['name'], recipient_name=instructor['name'], recording_type_name=scheduled. recording_type, ), ) else: error = f'section_id of scheduled recordings was not found in SIS data: {scheduled}' app.logger.error(error) send_system_error_email(message=error)
def notify_instructors_recordings_scheduled(course, scheduled): email_template = EmailTemplate.get_template_by_type('recordings_scheduled') publish_type_name = NAMES_PER_PUBLISH_TYPE[scheduled.publish_type] recording_type_name = NAMES_PER_RECORDING_TYPE[scheduled.recording_type] BConnected().send( message=interpolate_email_content( course=course, publish_type_name=publish_type_name, recording_type_name=recording_type_name, templated_string=email_template.message, ), recipients=course['instructors'], section_id=course['sectionId'], subject_line=interpolate_email_content( course=course, publish_type_name=publish_type_name, recording_type_name=recording_type_name, templated_string=email_template.subject_line, ), template_type=email_template.template_type, term_id=course['termId'], )