def update_all_for_term(cls, term_id): app.logger.info('Starting alert update') enrollments_for_term = data_loch.get_enrollments_for_term(str(term_id)) no_activity_alerts_enabled = cls.no_activity_alerts_enabled() infrequent_activity_alerts_enabled = cls.infrequent_activity_alerts_enabled( ) for row in enrollments_for_term: enrollments = json.loads(row['enrollment_term']).get( 'enrollments', []) for enrollment in enrollments: cls.update_alerts_for_enrollment( row['sid'], term_id, enrollment, no_activity_alerts_enabled, infrequent_activity_alerts_enabled) if app.config['ALERT_HOLDS_ENABLED'] and str( term_id) == current_term_id(): holds = data_loch.get_sis_holds() for row in holds: hold_feed = json.loads(row['feed']) cls.update_hold_alerts(row['sid'], term_id, hold_feed.get('type'), hold_feed.get('reason')) if app.config['ALERT_WITHDRAWAL_ENABLED'] and str( term_id) == current_term_id(): profiles = data_loch.get_student_profiles() for row in profiles: profile_feed = json.loads(row['profile']) if 'withdrawalCancel' in (profile_feed.get('sisProfile') or {}): cls.update_withdrawal_cancel_alerts(row['sid'], term_id) app.logger.info('Alert update complete')
def put_notifications(student): sid = student['sid'] student['notifications'] = { 'note': [], 'alert': [], 'hold': [], 'requirement': [], } if app.config['FEATURE_FLAG_ADVISOR_APPOINTMENTS']: student['notifications']['appointment'] = [] for appointment in Appointment.get_appointments_per_sid(sid) or []: student['notifications']['appointment'].append({ **appointment.to_api_json(current_user.get_id()), **{ 'message': appointment.details, 'type': 'appointment', }, }) # The front-end requires 'type', 'message' and 'read'. Optional fields: id, status, createdAt, updatedAt. for note in get_advising_notes(sid) or []: message = note['body'] student['notifications']['note'].append({ **note, **{ 'message': message.strip() if message else None, 'type': 'note', }, }) for alert in Alert.current_alerts_for_sid(viewer_id=current_user.get_id(), sid=sid): student['notifications']['alert'].append({ **alert, **{ 'id': alert['id'], 'read': alert['dismissed'], 'type': 'alert', }, }) for row in get_sis_holds(sid): hold = json.loads(row['feed']) reason = hold.get('reason', {}) student['notifications']['hold'].append({ **hold, **{ 'createdAt': hold.get('fromDate'), 'message': join_if_present('. ', [ reason.get('description'), reason.get('formalDescription') ]), 'read': True, 'type': 'hold', }, }) degree_progress = student.get('sisProfile', {}).get('degreeProgress', {}) if degree_progress: for key, requirement in degree_progress.get('requirements', {}).items(): student['notifications']['requirement'].append( { **requirement, **{ 'type': 'requirement', 'message': requirement['name'] + ' ' + requirement['status'], 'read': True, }, })