Пример #1
0
def get_non_legacy_advising_appointments(sid):
    appointments_by_id = {}
    for row in Appointment.get_appointments_per_sid(sid):
        appointment = row.__dict__
        appointment_id = appointment['id']
        event = appointment_event_to_json(appointment_id, row.status)
        appointments_by_id[str(appointment_id)] = appointment_to_compatible_json(
            appointment=appointment,
            topics=[t.to_api_json() for t in row.topics if not t.deleted_at],
            event=event,
        )
    return appointments_by_id
Пример #2
0
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,
                    },
                })