コード例 #1
0
ファイル: profile.py プロジェクト: fanglinfang/myuw
    def GET(self, request):
        """
        GET returns 200 with the student account balances
        of the current user
        """

        timer = Timer()
        logger = logging.getLogger(__name__)
        profile = get_profile_of_current_user()
        if profile is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)

        response = profile.json_data()
        response['campus'] = get_base_campus(request)

        enrollment = get_current_quarter_enrollment(request)
        if enrollment is not None:
            response['is_grad_student'] = is_grad_student()
            response['class_level'] = enrollment.class_level
            if len(enrollment.majors) > 0:
                response['majors'] = []
                for major in enrollment.majors:
                    response['majors'].append(major.json_data())

            if len(enrollment.minors) > 0:
                response['minors'] = []
                for minor in enrollment.minors:
                    response['minors'].append(minor.json_data())

        logger.debug(response)
        return HttpResponse(json.dumps(response))
コード例 #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
ファイル: textbook.py プロジェクト: vegitron/myuw
    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)
コード例 #4
0
ファイル: uwemail.py プロジェクト: fanglinfang/myuw
    def GET(self, request):
        """
        GET returns 200 with the uwemail forwarding
        of the current user
        """

        timer = Timer()
        logger = logging.getLogger(__name__)
        my_uwemail_forwarding = get_email_forwarding_for_current_user()
        if my_uwemail_forwarding is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        resp_json = my_uwemail_forwarding.json_data()
        logger.debug(resp_json)
        return HttpResponse(json.dumps(resp_json))
コード例 #5
0
ファイル: category_links.py プロジェクト: fanglinfang/myuw
    def GET(self, request, category_id):
        """
        GET returns 200 with links for the given category
        """
        timer = Timer()
        logger = logging.getLogger('views.api.CategoryLinks.GET')
        links = get_links_for_category(category_id, request)
        if not links:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        link_data = self._group_links_by_subcategory(links)
        category_name = links[0].category_name

        log_success_response(logger, timer)
        return HttpResponse(json.dumps({"link_data": link_data,
                                        "category_name": category_name}))
コード例 #6
0
ファイル: library.py プロジェクト: fanglinfang/myuw
    def GET(self, request):
        """
        GET returns 200 with the library account balances
        of the current user
        """

        timer = Timer()
        logger = logging.getLogger(__name__)
        myaccount = get_account_info_for_current_user()
        if myaccount is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        resp_json = myaccount.json_data(use_abbr_week_month_day_format=True)
        logger.debug(resp_json)
        return HttpResponse(json.dumps(resp_json))
コード例 #7
0
ファイル: hfs.py プロジェクト: fanglinfang/myuw
    def GET(self, request):
        """
        GET returns 200 with the HFS account balances
        of the current user
        """

        timer = Timer()
        logger = logging.getLogger(__name__)
        balances = get_account_balances_for_current_user()

        if balances is None:
            log_data_not_found_response(logger, timer)
            return HttpResponse('{}')

        log_success_response(logger, timer)
        resp_json = balances.json_data(use_custom_date_format=True)
        logger.debug(resp_json)
        return HttpResponse(json.dumps(resp_json))
コード例 #8
0
    def make_http_resp(self, timer, term, request, summer_term=None):
        """
        @return class schedule data in json format
                status 404: no schedule found (not registered)
        """
        schedule = get_schedule_by_term(request, term)

        if summer_term is None:
            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, timer)
            return data_not_found()

        resp_data = load_schedule(request, schedule, summer_term)
        log_success_response(logger, timer)
        return HttpResponse(json.dumps(resp_data))
コード例 #9
0
ファイル: base_schedule.py プロジェクト: vegitron/myuw
    def make_http_resp(self, timer, term, request, summer_term=None):
        """
        @return class schedule data in json format
                status 404: no schedule found (not registered)
        """
        schedule = get_schedule_by_term(request, term)

        if summer_term is None:
            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, timer)
            return data_not_found()

        resp_data = load_schedule(request, schedule, summer_term)
        log_success_response(logger, timer)
        return HttpResponse(json.dumps(resp_data))
コード例 #10
0
ファイル: thrive.py プロジェクト: vegitron/myuw
    def GET(self, request):
        """
        GET returns 200 with current thrive message
        for the current user if they are a first year student
        """
        timer = Timer()
        logger = logging.getLogger(__name__)
        message = None
        if is_thrive_viewer():
            if request.GET.get('history', False):
                message = get_previous_messages(request)
            else:
                message = get_current_message(request)

        if message is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        return HttpResponse(json.dumps(message))
コード例 #11
0
ファイル: category_links.py プロジェクト: kroberts-uw/myuw
    def GET(self, request, category_id):
        """
        GET returns 200 with links for the given category
        """
        timer = Timer()
        logger = logging.getLogger('views.api.CategoryLinks.GET')
        links = get_links_for_category(category_id, request)
        if not links:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        link_data = self._group_links_by_subcategory(links)
        category_name = links[0].category_name

        log_success_response(logger, timer)
        return HttpResponse(
            json.dumps({
                "link_data": link_data,
                "category_name": category_name
            }))
コード例 #12
0
ファイル: thrive.py プロジェクト: kroberts-uw/myuw
    def GET(self, request):
        """
        GET returns 200 with current thrive message
        for the current user if they are a first year student
        """
        timer = Timer()
        logger = logging.getLogger(__name__)
        message = None
        if is_thrive_viewer():
            if request.GET.get('history', False):
                message = get_previous_messages(request)
            else:
                message = get_current_message(request)

        if message is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        return HttpResponse(json.dumps(message))
コード例 #13
0
ファイル: thrive.py プロジェクト: mattventura/myuw
    def GET(self, request):
        """
        GET returns 200 with current thrive message
        for the current user if they are a first year student
        """

        # Hack we're using to identify firstyear students, will need to
        # re-evaluate for AUT 2016
        is_firstyear = is_mandatory_switch_user()

        timer = Timer()
        logger = logging.getLogger(__name__)
        message = None
        if is_firstyear:
            message = get_current_message(request)
        if message is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        return HttpResponse(json.dumps(message))
コード例 #14
0
ファイル: finance.py プロジェクト: fanglinfang/myuw
    def GET(self, request):
        """
        GET returns 200 with the student account balances
        of the current user
        """

        timer = Timer()
        logger = logging.getLogger(__name__)
        balances = get_account_balances_for_current_user()

        if balances is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        logger.debug(balances.json_data())
        date = get_tuition_due_date()
        response = balances.json_data()
        response['tuition_due'] = str(date)

        return HttpResponse(json.dumps(response))
コード例 #15
0
ファイル: textbook.py プロジェクト: fanglinfang/myuw
    def respond(self, year, quarter, summer_term):
        timer = Timer()
        logger = logging.getLogger(__name__)

        term = get_quarter(year=year, quarter=quarter)
        schedule = get_schedule_by_term(term)
        if summer_term is not None:
            summer_term = summer_term.replace(",", "")
            filter_schedule_sections_by_summer_term(schedule, summer_term)

        book_data = get_textbook_by_schedule(schedule)
        if book_data is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        verba_link = get_verba_link_by_schedule(schedule)

        by_sln = index_by_sln(book_data)
        by_sln["verba_link"] = verba_link
        log_success_response(logger, timer)
        return HttpResponse(json.dumps(by_sln))
コード例 #16
0
ファイル: iasystem.py プロジェクト: mattventura/myuw
    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)
コード例 #17
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)
コード例 #18
0
ファイル: base_schedule.py プロジェクト: fanglinfang/myuw
    def make_http_resp(self, logger, timer, term, request, summer_term=None):
        if term is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        schedule = get_schedule_by_term(term)
        if schedule is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        if not schedule.json_data():
            log_data_not_found_response(logger, timer)
            return HttpResponse({})

        if summer_term is None:
            summer_term = get_current_summer_term_in_schedule(schedule, request)

        resp_data = load_schedule(request, schedule, summer_term)
        if resp_data is None:
            log_data_not_found_response(logger, timer)
            return data_not_found()

        log_success_response(logger, timer)
        return HttpResponse(json.dumps(resp_data))
コード例 #19
0
ファイル: page.py プロジェクト: fanglinfang/myuw
def index(request,
          year=None,
          quarter=None,
          summer_term=None):

    netid = UserService().get_user()
    if not netid:
        log_invalid_netid_response(logger, timer)
        return invalid_session()

    if _is_mobile(request):
        # On mobile devices, all students get the current myuw.  Non-students
        # are sent to the legacy site.
        if not is_student():
            return redirect_to_legacy_site()
    else:
        # On the desktop, we're migrating users over.  There are 2 classes of
        # users - mandatory and opt-in switchers.  The mandatory users, who
        # are users who haven't been at the UW long enough to be accustomed to
        # the existing myuw.
        # The other class of users can opt to use the legacy myuw instead.
        # Check to see if they have a set preference, and if not, keep them on
        # the new version
        if not is_mandatory_switch_user():
            if is_optin_switch_user():
                if has_legacy_preference():
                    return redirect_to_legacy_site()
            else:
                return redirect_to_legacy_site()

    timer = Timer()
    logger = logging.getLogger('myuw.views.page.index')

    context = {
        "year": year,
        "quarter": quarter,
        "summer_term": summer_term,
        "home_url": "/",
        "err": None,
        "user": {
            "netid": None,
            "affiliations": get_all_affiliations(request)
        },
        "card_display_dates": get_card_visibilty_date_values(request),
    }

    context["user"]["session_key"] = request.session.session_key
    log_session(netid, request.session.session_key, request)
    my_uwemail_forwarding = get_email_forwarding_for_current_user()
    if my_uwemail_forwarding is not None and my_uwemail_forwarding.is_active():
        c_user = context["user"]
        c_user["email_is_uwgmail"] = my_uwemail_forwarding.is_uwgmail()
        c_user["email_is_uwlive"] = my_uwemail_forwarding.is_uwlive()

    context["user"]["netid"] = netid
    if year is None or quarter is None:
        cur_term = get_current_quarter(request)
        if cur_term is None:
            context["err"] = "No current quarter data!"
            log_data_not_found_response(logger, timer)
        else:
            context["year"] = cur_term.year
            context["quarter"] = cur_term.quarter
    else:
        pass
    log_success_response_with_affiliation(logger, timer, request)
    return render_to_response("index.html",
                              context,
                              context_instance=RequestContext(request))