예제 #1
0
def _get_loch_notes_search_results(loch_results, search_terms):
    results = []
    if not loch_results:
        return results
    sids = list(
        set([
            row.get('advisor_sid') for row in loch_results
            if row.get('advisor_sid') is not None
        ]))
    calnet_advisor_feeds = get_calnet_users_for_csids(app, sids)
    for note in loch_results:
        advisor_feed = calnet_advisor_feeds.get(note.get('advisor_sid'))
        if advisor_feed:
            advisor_name = advisor_feed.get('name') or join_if_present(
                ' ', [
                    advisor_feed.get('first_name'),
                    advisor_feed.get('last_name')
                ])
        else:
            advisor_name = None
        note_body = (note.get('note_body') or '').strip() or join_if_present(
            ', ', [note.get('note_category'),
                   note.get('note_subcategory')])
        results.append({
            'id':
            note.get('id'),
            'studentSid':
            note.get('sid'),
            'studentUid':
            note.get('uid'),
            'studentName':
            join_if_present(' ',
                            [note.get('first_name'),
                             note.get('last_name')]),
            'advisorSid':
            note.get('advisor_sid'),
            'advisorName':
            advisor_name or join_if_present(' ', [
                note.get('advisor_first_name'),
                note.get('advisor_last_name')
            ]),
            'noteSnippet':
            search_result_text_snippet(note_body, search_terms,
                                       TEXT_SEARCH_PATTERN),
            'createdAt':
            resolve_sis_created_at(note),
            'updatedAt':
            resolve_sis_updated_at(note),
        })
    return results
예제 #2
0
def _get_loch_notes_search_results(loch_results, search_terms):
    results = []
    calnet_advisor_feeds = get_calnet_users_for_csids(
        app,
        list(
            set([
                row.get('advisor_sid') for row in loch_results
                if row.get('advisor_sid') is not None
            ])),
    )
    for row in loch_results:
        note = {camelize(key): row[key] for key in row.keys()}
        advisor_feed = calnet_advisor_feeds.get(note.get('advisorSid'))
        advisor_name = join_if_present(
            ' ', [advisor_feed.get('firstName'),
                  advisor_feed.get('lastName')]) if advisor_feed else None
        note_body = (note.get('noteBody') or '').strip() or join_if_present(
            ', ', [note.get('noteCategory'),
                   note.get('noteSubcategory')])
        results.append({
            'id':
            note.get('id'),
            'studentSid':
            note.get('sid'),
            'studentUid':
            note.get('uid'),
            'studentName':
            join_if_present(' ', [note.get('firstName'),
                                  note.get('lastName')]),
            'advisorSid':
            note.get('advisorSid'),
            'advisorName':
            advisor_name or join_if_present(
                ' ',
                [note.get('advisorFirstName'),
                 note.get('advisorLastName')]),
            'noteSnippet':
            search_result_text_snippet(note_body, search_terms,
                                       NOTE_SEARCH_PATTERN),
            'createdAt':
            _resolve_created_at(note),
            'updatedAt':
            _resolve_updated_at(note),
        })
    return results
예제 #3
0
def _get_local_notes_search_results(local_results, cutoff, search_terms):
    results = []
    student_rows = data_loch.get_basic_student_data(
        [row.get('sid') for row in local_results])
    students_by_sid = {r.get('sid'): r for r in student_rows}
    for row in local_results:
        note = {camelize(key): row[key] for key in row.keys()}
        sid = note.get('sid')
        student_row = students_by_sid.get(sid, {})
        if student_row:
            omit_note_body = note.get(
                'isPrivate') and not current_user.can_access_private_notes
            subject = note.get('subject')
            text = subject if omit_note_body else join_if_present(
                ' - ', [subject, note.get('body')])
            results.append({
                'id':
                note.get('id'),
                'studentSid':
                sid,
                'studentUid':
                student_row.get('uid'),
                'studentName':
                join_if_present(' ', [
                    student_row.get('first_name'),
                    student_row.get('last_name')
                ]),
                'advisorUid':
                note.get('authorUid'),
                'advisorName':
                note.get('authorName'),
                'noteSnippet':
                search_result_text_snippet(text, search_terms,
                                           TEXT_SEARCH_PATTERN),
                'createdAt':
                _isoformat(note, 'createdAt'),
                'updatedAt':
                _isoformat(note, 'updatedAt'),
            })
        if len(results) == cutoff:
            break
    return results
예제 #4
0
def _to_json(search_terms, search_result):
    appointment_id = search_result['id']
    sid = search_result['student_sid']

    api_json = {
        'id':
        appointment_id,
        'advisorName':
        search_result['advisor_name'],
        'advisorRole':
        search_result['advisor_role'],
        'advisorUid':
        search_result['advisor_uid'],
        'advisorDeptCodes':
        search_result['advisor_dept_codes'],
        'createdAt':
        _isoformat(search_result['created_at']),
        'createdBy':
        search_result['created_by'],
        'deptCode':
        search_result['dept_code'],
        'details':
        search_result['details'],
        'detailsSnippet':
        search_result_text_snippet(search_result['details'], search_terms,
                                   TEXT_SEARCH_PATTERN),
        'studentSid':
        sid,
        'updatedAt':
        _isoformat(search_result['updated_at']),
        'updatedBy':
        search_result['updated_by'],
    }
    return {
        **api_json,
        **appointment_event_to_json(appointment_id, search_result['status']),
        **_student_to_json(sid),
    }
예제 #5
0
def _get_loch_appointments_search_results(loch_results, search_terms):
    results = []
    if not loch_results:
        return results
    sids = list(set([row.get('advisor_sid') for row in loch_results if row.get('advisor_sid') is not None]))
    calnet_advisor_feeds = get_calnet_users_for_csids(app, sids)
    for appointment in loch_results:
        advisor_feed = calnet_advisor_feeds.get(appointment.get('advisor_sid'))
        if advisor_feed:
            advisor_name = advisor_feed.get('name') or join_if_present(' ', [advisor_feed.get('firstName'), advisor_feed.get('lastName')])
        else:
            advisor_name = None
        details = (appointment.get('note_body') or '').strip() or join_if_present(
            ', ',
            [appointment.get('note_category'), appointment.get('note_subcategory')],
        )
        student_sid = appointment.get('sid')
        results.append({
            'id': appointment.get('id'),
            'advisorName': advisor_name or join_if_present(' ', [appointment.get('advisor_first_name'), appointment.get('advisor_last_name')]),
            'advisorRole': advisor_feed.get('title'),
            'advisorUid': advisor_feed.get('uid'),
            'advisorDeptCodes': [dept['code'] for dept in advisor_feed.get('departments')],
            'createdAt': resolve_sis_created_at(appointment),
            'details': details,
            'detailsSnippet': search_result_text_snippet(details, search_terms, TEXT_SEARCH_PATTERN),
            'studentSid': student_sid,
            'updatedAt': resolve_sis_updated_at(appointment),
            'student': {
                'uid': appointment.get('uid'),
                'firstName': appointment.get('first_name'),
                'lastName': appointment.get('last_name'),
                'sid': student_sid,
            },
        })
    return results
예제 #6
0
def _to_json(search_terms, search_result):
    appointment_id = search_result['id']
    student = data_loch.get_student_by_sid(search_result['student_sid'])
    api_json = {
        'id':
        appointment_id,
        'advisorName':
        search_result['advisor_name'],
        'advisorRole':
        search_result['advisor_role'],
        'advisorUid':
        search_result['advisor_uid'],
        'advisorDeptCodes':
        search_result['advisor_dept_codes'],
        'createdAt':
        _isoformat(search_result['created_at']),
        'createdBy':
        search_result['created_by'],
        'deptCode':
        search_result['dept_code'],
        'details':
        search_result['details'],
        'detailsSnippet':
        search_result_text_snippet(search_result['details'], search_terms,
                                   APPOINTMENT_SEARCH_PATTERN),
        'student': {camelize(key): student[key]
                    for key in student.keys()},
        'updatedAt':
        _isoformat(search_result['updated_at']),
        'updatedBy':
        search_result['updated_by'],
    }
    return {
        **api_json,
        **_appointment_event_to_json(appointment_id, search_result['status']),
    }