def get_courses_ready_to_schedule(approvals, term_id): ready_to_schedule = [] scheduled_section_ids = [ s.section_id for s in Scheduled.get_all_scheduled(term_id=term_id) ] unscheduled_approvals = [ approval for approval in approvals if approval.section_id not in scheduled_section_ids ] if unscheduled_approvals: courses = SisSection.get_courses( section_ids=[a.section_id for a in unscheduled_approvals], term_id=term_id) courses_per_section_id = dict( (int(course['sectionId']), course) for course in courses) admin_user_uids = set([ user.uid for user in AdminUser.all_admin_users(include_deleted=True) ]) for section_id, uids in _get_uids_per_section_id( approvals=unscheduled_approvals).items(): if admin_user_uids.intersection(set(uids)): ready_to_schedule.append(courses_per_section_id[section_id]) else: course = courses_per_section_id[section_id] necessary_uids = [i['uid'] for i in course['instructors']] if all(uid in uids for uid in necessary_uids): ready_to_schedule.append( courses_per_section_id[section_id]) return ready_to_schedule
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 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]) _alert_admin_of_instructor_change( courses=courses, approval_uids_per_section_id=_approval_uids_per_section_id( scheduled=all_scheduled, term_id=term_id, ), ) _alert_admin_of_room_change( courses=courses, scheduled_rooms_per_section_id= _scheduled_locations_per_section_id(all_scheduled), )
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 get_courses_ready_to_schedule(approvals, term_id): ready_to_schedule = [] scheduled_section_ids = [ s.section_id for s in Scheduled.get_all_scheduled(term_id=term_id) ] unscheduled_approvals = [ approval for approval in approvals if approval.section_id not in scheduled_section_ids ] if unscheduled_approvals: courses = SisSection.get_courses( section_ids=[a.section_id for a in unscheduled_approvals], term_id=term_id) courses_per_section_id = dict( (int(course['sectionId']), course) for course in courses) admin_user_uids = set([ user.uid for user in AdminUser.all_admin_users(include_deleted=True) ]) for section_id, approved_by_uids in _get_uids_per_section_id( approvals=unscheduled_approvals).items(): course = courses_per_section_id.get(section_id) if not course: continue if len(course.get('meetings', {}).get('eligible', [])) != 1: app.logger.warn( f'Unique meeting pattern not found for section id {section_id}; will not schedule.' ) continue if admin_user_uids.intersection(set(approved_by_uids)): ready_to_schedule.append(course) else: necessary_uids = [i['uid'] for i in course['instructors']] if all(uid in approved_by_uids for uid in necessary_uids): ready_to_schedule.append(course) return ready_to_schedule
def test_total_scheduled_count(self, client, admin_session): """The courses report includes valid total_scheduled_count.""" report = self._api_courses_report(client, term_id=self.term_id) assert report['totalScheduledCount'] == len(Scheduled.get_all_scheduled(self.term_id))
def courses_report(term_id): return tolerant_jsonify({ 'totalScheduledCount': len(Scheduled.get_all_scheduled(term_id=term_id)), })