Example #1
0
def search_students():
    params = request.get_json()
    if is_unauthorized_search(params):
        raise ForbiddenRequestError(
            'You are unauthorized to access student data managed by other departments'
        )
    search_phrase = util.get(params, 'searchPhrase', '').strip()
    if not len(search_phrase):
        raise BadRequestError('Invalid or empty search input')
    results = search_for_students(
        include_profiles=True,
        search_phrase=search_phrase.replace(',', ' '),
        is_active_asc=_convert_asc_inactive_arg(
            util.get(params, 'isInactiveAsc')),
        order_by=util.get(params, 'orderBy', None),
        offset=util.get(params, 'offset', 0),
        limit=util.get(params, 'limit', 50),
    )
    alert_counts = Alert.current_alert_counts_for_viewer(current_user.id)
    students = results['students']
    add_alert_counts(alert_counts, students)
    return tolerant_jsonify({
        'students': students,
        'totalStudentCount': results['totalStudentCount'],
    })
def _student_search(search_phrase, params, order_by):
    student_results = search_for_students(
        search_phrase=search_phrase.replace(',', ' '),
        order_by=order_by,
        offset=util.get(params, 'offset', 0),
        limit=util.get(params, 'limit', 50),
    )
    students = student_results['students']
    sids = [s['sid'] for s in students]
    alert_counts = Alert.current_alert_counts_for_sids(current_user.get_id(),
                                                       sids)
    add_alert_counts(alert_counts, students)
    return {
        'students': students,
        'totalStudentCount': student_results['totalStudentCount'],
    }
Example #3
0
def my_curated_cohorts():
    alert_counts = Alert.current_alert_counts_for_viewer(current_user.id)
    curated_cohorts = CuratedCohort.get_curated_cohorts_by_owner_id(
        current_user.id)
    curated_cohorts = sorted(curated_cohorts,
                             key=lambda curated_cohort: curated_cohort.name)
    curated_cohorts = [c.to_api_json(sids_only=True) for c in curated_cohorts]
    for curated_cohort in curated_cohorts:
        students = curated_cohort['students']
        api_util.add_alert_counts(alert_counts, students)
        # Only get detailed data for students with alerts.
        sids_with_alerts = [s['sid'] for s in students if s.get('alertCount')]
        students_with_alerts = get_summary_student_profiles(sids_with_alerts)
        for data in students_with_alerts:
            data['alertCount'] = next(
                s.get('alertCount') for s in students
                if s['sid'] == data['sid'])
            api_util.strip_analytics(data)
        curated_cohort['students'] = api_util.sort_students_by_name(
            students_with_alerts)
    return tolerant_jsonify(curated_cohorts)
Example #4
0
def get_students():
    params = request.get_json()
    if is_unauthorized_search(params):
        raise ForbiddenRequestError(
            'You are unauthorized to access student data managed by other departments'
        )
    results = query_students(
        advisor_ldap_uids=util.get(params, 'advisorLdapUids'),
        coe_prep_statuses=util.get(params, 'coePrepStatuses'),
        ethnicities=util.get(params, 'ethnicities'),
        genders=util.get(params, 'genders'),
        gpa_ranges=util.get(params, 'gpaRanges'),
        group_codes=util.get(params, 'groupCodes'),
        include_profiles=True,
        is_active_asc=_convert_asc_inactive_arg(
            util.get(params, 'isInactiveAsc')),
        in_intensive_cohort=util.to_bool_or_none(
            util.get(params, 'inIntensiveCohort')),
        last_name_range=_get_name_range_boundaries(
            util.get(params, 'lastNameRange')),
        levels=util.get(params, 'levels'),
        limit=util.get(params, 'limit', 50),
        majors=util.get(params, 'majors'),
        offset=util.get(params, 'offset', 0),
        order_by=util.get(params, 'orderBy', None),
        underrepresented=util.get(params, 'underrepresented'),
        unit_ranges=util.get(params, 'unitRanges'),
    )
    if results is None:
        raise BadRequestError('Invalid search criteria')
    alert_counts = Alert.current_alert_counts_for_viewer(current_user.id)
    students = results['students'] if results else []
    add_alert_counts(alert_counts, students)
    return tolerant_jsonify({
        'students':
        students,
        'totalStudentCount':
        results['totalStudentCount'] if results else 0,
    })