Пример #1
0
    def respond(self, request, year, quarter, summer_term):
        timer = Timer()
        try:
            if not is_student():
                log_msg(logger, timer, "Not a student, abort!")
                return data_not_found()

            term = get_specific_term(year=year, quarter=quarter)
            schedule = get_schedule_by_term(request, term)

            if summer_term is not None and len(summer_term) > 0:
                summer_term = summer_term.replace(",", "")
                filter_schedule_sections_by_summer_term(schedule, summer_term)

            if len(schedule.sections) == 0:
                log_data_not_found_response(logger, timer)
                return data_not_found()

            book_data = get_textbook_by_schedule(schedule)
            by_sln = index_by_sln(book_data)

            try:
                verba_link = get_verba_link_by_schedule(schedule)
                by_sln["verba_link"] = verba_link
            except DataFailureException as ex:
                if ex.status != 404:
                    raise

            log_success_response(logger, timer)
            return HttpResponse(json.dumps(by_sln))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #2
0
    def respond(self, request, year, quarter, summer_term):
        timer = Timer()
        try:
            if not is_student():
                log_msg(logger, timer, "Not a student, abort!")
                return data_not_found()

            term = get_specific_term(year=year, quarter=quarter)
            schedule = get_schedule_by_term(request, term)

            if summer_term is not None and len(summer_term) > 0:
                summer_term = summer_term.replace(",", "")
                filter_schedule_sections_by_summer_term(schedule, summer_term)

            if len(schedule.sections) == 0:
                log_data_not_found_response(logger, timer)
                return data_not_found()

            book_data = get_textbook_by_schedule(schedule)
            by_sln = index_by_sln(book_data)

            try:
                verba_link = get_verba_link_by_schedule(schedule)
                by_sln["verba_link"] = verba_link
            except DataFailureException as ex:
                if ex.status != 404:
                    raise

            log_success_response(logger, timer)
            return HttpResponse(json.dumps(by_sln))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #3
0
def get_all_affiliations(request):
    """
    return a dictionary of affiliation indicators.
    ["student"]: True if the user is currently an UW student.
    ["grad"]: True if the user is currently an UW graduate student.
    ["undergrad"]: True if the user is currently an UW undergraduate student.
    ["pce"]: True if the user is currently an UW PCE student.
    ["employee"]: True if the user is currently a uw employee.
    ["stud_employee"]: True if the user is currently a student employee.
    ["faculty"]: True if the user is currently faculty.
    ["seattle"]: True if the user is an UW Seattle student
                 in the current quarter.
    ["bothell"]: True if the user is an UW Bothell student
                 in the current quarter.
    ["tacoma"]: True if the user is an UW Tacoma student
                in the current quarter.
    ["official_seattle"]: True if the user is an UW Seattle student
                 according to the SWS Enrollment.
    ["official_bothell"]: True if the user is an UW Bothell student
                 according to the SWS Enrollment.
    ["official_tacoma"]: True if the user is an UW Tacoma student
                according to the SWS Enrollment.
    """

    if hasattr(request, 'myuw_user_affiliations'):
        return request.myuw_user_affiliations

    enrolled_campuses = get_current_quarter_course_campuses(request)
    is_fyp = False
    try:
        is_fyp = is_thrive_viewer()
    except Exception:
        # This fails in unit tests w/o userservice
        pass

    data = {
        "grad": is_grad_student(),
        "undergrad": is_undergrad_student(),
        "student": is_student(),
        "pce": is_pce_student(),
        "stud_employee": is_student_employee(),
        "employee": is_employee(),
        "fyp": is_fyp,
        "faculty": is_faculty(),
        "seattle": enrolled_campuses["seattle"] or is_seattle_student(),
        "bothell": enrolled_campuses["bothell"] or is_bothell_student(),
        "tacoma": enrolled_campuses["tacoma"] or is_tacoma_student(),
    }
    # add 'official' campus info
    official_campuses = _get_official_campuses(get_main_campus(request))
    data = dict(data.items() + official_campuses.items())
    # Note:
    #    As the UW Affiliation group (gws) only knows about one campus,
    #    we use registered sections in the current quarter
    #    to determine the campuses.
    log_info(logger, data)
    request.myuw_user_affiliations = data
    return data
Пример #4
0
def get_all_affiliations(request):
    """
    return a dictionary of affiliation indicators.
    ["student"]: True if the user is currently an UW student.
    ["grad"]: True if the user is currently an UW graduate student.
    ["undergrad"]: True if the user is currently an UW undergraduate student.
    ["pce"]: True if the user is currently an UW PCE student.
    ["employee"]: True if the user is currently a uw employee.
    ["stud_employee"]: True if the user is currently a student employee.
    ["faculty"]: True if the user is currently faculty.
    ["seattle"]: True if the user is an UW Seattle student
                 in the current quarter.
    ["bothell"]: True if the user is an UW Bothell student
                 in the current quarter.
    ["tacoma"]: True if the user is an UW Tacoma student
                in the current quarter.
    ["official_seattle"]: True if the user is an UW Seattle student
                 according to the SWS Enrollment.
    ["official_bothell"]: True if the user is an UW Bothell student
                 according to the SWS Enrollment.
    ["official_tacoma"]: True if the user is an UW Tacoma student
                according to the SWS Enrollment.
    """

    if hasattr(request, 'myuw_user_affiliations'):
        return request.myuw_user_affiliations

    enrolled_campuses = get_current_quarter_course_campuses(request)
    is_fyp = False
    try:
        is_fyp = is_thrive_viewer()
    except Exception:
        # This fails in unit tests w/o userservice
        pass

    data = {"grad": is_grad_student(),
            "undergrad": is_undergrad_student(),
            "student": is_student(),
            "pce": is_pce_student(),
            "stud_employee": is_student_employee(),
            "employee": is_employee(),
            "fyp": is_fyp,
            "faculty": is_faculty(),
            "seattle": enrolled_campuses["seattle"] or is_seattle_student(),
            "bothell": enrolled_campuses["bothell"] or is_bothell_student(),
            "tacoma": enrolled_campuses["tacoma"] or is_tacoma_student(),
            }
    # add 'official' campus info
    official_campuses = _get_official_campuses(get_main_campus(request))
    data = dict(data.items() + official_campuses.items())
    # Note:
    #    As the UW Affiliation group (gws) only knows about one campus,
    #    we use registered sections in the current quarter
    #    to determine the campuses.
    log_info(logger, data)
    request.myuw_user_affiliations = data
    return data
Пример #5
0
    def GET(self, request):
        """
        GET returns 200 with a list of notices for the current user
                        with an empty array if no notice.
                    543 for data error
        """
        timer = Timer()
        try:
            notice_json = []
            if is_student():
                notice_json = get_json_for_notices(
                    request, get_notices_for_current_user())

            log_success_response(logger, timer)
            return HttpResponse(json.dumps(notice_json))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #6
0
    def GET(self, request):
        """
        GET returns 200 with a list of notices for the current user
                        with an empty array if no notice.
                    543 for data error
        """
        timer = Timer()
        try:
            notice_json = []
            if is_student():
                notice_json = get_json_for_notices(
                    request, get_notices_for_current_user())

            log_success_response(logger, timer)
            return HttpResponse(json.dumps(notice_json))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #7
0
    def GET(self, request):
        """
        GET returns 200 with the student account balances
        of the current user
        """
        timer = Timer()
        try:
            if not is_student():
                log_msg(logger, timer, "Not a student, abort!")
                return data_not_found()

            balances = get_account_balances_for_current_user()

            date = get_tuition_due_date()
            response = balances.json_data()
            response['tuition_due'] = str(date)

            log_success_response(logger, timer)
            return HttpResponse(json.dumps(response))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #8
0
    def GET(self, request):
        """
        GET returns 200 with the student account balances
        of the current user
        """
        timer = Timer()
        try:
            if not is_student():
                log_msg(logger, timer, "Not a student, abort!")
                return data_not_found()

            balances = get_account_balances_for_current_user()

            date = get_tuition_due_date()
            response = balances.json_data()
            response['tuition_due'] = str(date)

            log_success_response(logger, timer)
            return HttpResponse(json.dumps(response))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #9
0
    def GET(self, request):
        """
        GET /api/v1/ias/
        """
        timer = Timer()
        try:
            dao_class = getattr(settings,
                                "RESTCLIENTS_IASYSTEM_DAO_CLASS",
                                MOCKDAO)
            if dao_class == MOCKDAO and\
                    get_netid_of_current_user() == "eight":
                time.sleep(10)

            if not is_student():
                log_msg(logger, timer, "Not a student, abort!")
                return data_not_found()

            if not in_coursevel_fetch_window(request):
                # The window starts: 7 days before last inst
                # ends: the midnight at the end of current term
                # grade submission deadline
                log_msg(logger, timer, "Not in fetching window")
                return data_not_found()
            term = get_current_quarter(request)
            schedule = get_schedule_by_term(term)

            summer_term = get_current_summer_term_in_schedule(
                schedule, request)

            filter_schedule_sections_by_summer_term(schedule, summer_term)
            if len(schedule.sections) == 0:
                log_data_not_found_response(logger, time)
                return data_not_found()

            resp_data = load_course_eval(request, schedule, summer_term)
            log_success_response(logger, timer)
            return HttpResponse(json.dumps(resp_data))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #10
0
    def GET(self, request):
        """
        GET /api/v1/ias/
        """
        timer = Timer()
        try:
            dao_class = getattr(settings,
                                "RESTCLIENTS_IASYSTEM_DAO_CLASS",
                                MOCKDAO)
            if dao_class == MOCKDAO and\
                    get_netid_of_current_user() == "eight":
                time.sleep(10)

            if not is_student():
                log_msg(logger, timer, "Not a student, abort!")
                return data_not_found()

            if not in_coursevel_fetch_window(request):
                # The window starts: 7 days before last inst
                # ends: the midnight at the end of current term
                # grade submission deadline
                log_msg(logger, timer, "Not in fetching window")
                return data_not_found()
            term = get_current_quarter(request)
            schedule = get_schedule_by_term(request, term)

            summer_term = get_current_summer_term_in_schedule(
                schedule, request)

            filter_schedule_sections_by_summer_term(schedule, summer_term)
            if len(schedule.sections) == 0:
                log_data_not_found_response(logger, time)
                return data_not_found()

            resp_data = load_course_eval(request, schedule, summer_term)
            log_success_response(logger, timer)
            return HttpResponse(json.dumps(resp_data))
        except Exception:
            return handle_exception(logger, timer, traceback)
Пример #11
0
def log_session(netid, session_key, request):
    if session_key is None:
        session_key = ''

    session_hash = hashlib.md5(session_key).hexdigest()
    log_entry = {
        'netid': netid,
        'session_key': session_hash,
        'class_level': None,
        'is_grad': None,
        'is_ugrad': None,
        'is_student': None,
        'campus': None
    }
    try:
        level = get_current_quarter_enrollment(request).class_level
        log_entry['class_level'] = level
        is_mobile = request.is_mobile or request.is_tablet
        log_entry['is_mobile'] = bool(is_mobile)
    except Exception:
        pass
    try:
        log_entry['is_grad'] = is_grad_student()
    except Exception:
        pass
    try:
        log_entry['is_ugrad'] = is_undergrad_student()
    except Exception:
        pass
    try:
        log_entry['is_student'] = is_student()
    except Exception:
        pass
    try:
        log_entry['campus'] = get_base_campus(request)
    except Exception:
        pass
    logger.info(json.dumps(log_entry))
Пример #12
0
def log_session(netid, session_key, request):
    if session_key is None:
        session_key = ''

    session_hash = hashlib.md5(session_key).hexdigest()
    log_entry = {'netid': netid,
                 'session_key': session_hash,
                 'class_level': None,
                 'is_grad': None,
                 'is_ugrad': None,
                 'is_student': None,
                 'campus': None}
    try:
        level = get_current_quarter_enrollment(request).class_level
        log_entry['class_level'] = level
        is_mobile = request.is_mobile or request.is_tablet
        log_entry['is_mobile'] = bool(is_mobile)
    except Exception:
        pass
    try:
        log_entry['is_grad'] = is_grad_student()
    except Exception:
        pass
    try:
        log_entry['is_ugrad'] = is_undergrad_student()
    except Exception:
        pass
    try:
        log_entry['is_student'] = is_student()
    except Exception:
        pass
    try:
        log_entry['campus'] = get_base_campus(request)
    except Exception:
        pass
    logger.info(json.dumps(log_entry))