Пример #1
0
def get_next_autumn_quarter_schedule(request):
    """
    Return the actively enrolled sections in the next autumn quarter
    """
    # MUWM-1981
    if get_next_autumn_quarter(request) == get_current_quarter(request):
        return None
    return get_schedule_by_term(request, get_next_autumn_quarter(request))
Пример #2
0
    def test_efs_before_end(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-09-01"
            cur_term = get_current_quarter(now_request)
            self.assertEqual(cur_term.year, 2013)
            self.assertEqual(cur_term.quarter, "autumn")

            cur_term = get_current_quarter(now_request)
            fall_efs_schedule = _get_schedule(regid, cur_term)
            self.assertIsNotNone(fall_efs_schedule)
            self.assertEqual(len(fall_efs_schedule.sections), 2)
Пример #3
0
def get_next_autumn_quarter_schedule(request):
    """
    Return the actively enrolled sections in the next autumn quarter
    """
    # MUWM-1981
    if get_next_autumn_quarter(request) == get_current_quarter(request):
        return None
    return get_schedule_by_term(get_next_autumn_quarter(request))
Пример #4
0
    def test_efs_before_end(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-09-01"
            cur_term = get_current_quarter(now_request)
            self.assertEqual(cur_term.year, 2013)
            self.assertEqual(cur_term.quarter, "autumn")

            cur_term = get_current_quarter(now_request)
            fall_efs_schedule = _get_schedule(regid, cur_term)
            self.assertIsNotNone(fall_efs_schedule)
            self.assertEqual(len(fall_efs_schedule.sections), 2)
Пример #5
0
    def test_current_quarter(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            now_request = RequestFactory().get("/")
            now_request.session = {}

            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "spring")

            now_request.session["myuw_override_date"] = "2013-04-01"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "spring")

            now_request.session["myuw_override_date"] = "2013-03-25"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "winter")

            now_request.session["myuw_override_date"] = "2013-03-26"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "winter")

            now_request.session["myuw_override_date"] = "2013-03-27"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "spring")

            now_request.session["myuw_override_date"] = "2013-03-31"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "spring")

            now_request.session["myuw_override_date"] = "2013-06-24"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "summer")

            # Spring's grade submission deadline is today, so we're not after
            # that, which is why this is an exception to the rule
            now_request.session["myuw_override_date"] = "2013-06-23"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "spring")

            now_request.session["myuw_override_date"] = "2013-06-18"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, "spring")
Пример #6
0
def _get_registered_future_quarters(request, next_quar_sche, next_autumn_sche):
    """
    Return the list of future quarters that
    has actively enrolled sections

    @param next_quar_sche: ClassSchedule object of a future quarter
    @param next_autumn_quar_sche: ClassSchedule object of the future
           autumn quarter if the next_quar_sche is of summer quarter
    """
    terms = []
    if next_quar_sche is not None and len(next_quar_sche.sections) > 0:
        next_quarter = next_quar_sche.term

        if next_quarter.quarter == "summer":
            sumr_tms = _get_registered_summer_terms(next_quar_sche.sections)
            # MUWM-3010
            # Filter out A-term and Full-term sections once summer term has
            # started.
            # Filter out B-term courses once B-term has started.
            current = get_current_quarter(request)
            now = get_comparison_date(request)
            summer_started = False
            bterm_started = False

            has_b = sumr_tms[B_TERM]
            if current.quarter == "summer":
                if now >= current.first_day_quarter:
                    summer_started = True

                if now >= current.bterm_first_date:
                    bterm_started = True

            if not summer_started:
                if sumr_tms[A_TERM] or sumr_tms[FULL_TERM] and has_b:
                    terms.append(_get_future_term_json(next_quarter,
                                                       "a-term",
                                                       sumr_tms))

            if not bterm_started:
                if has_b or sumr_tms[FULL_TERM] and sumr_tms[A_TERM]:
                    terms.append(_get_future_term_json(next_quarter,
                                                       "b-term",
                                                       sumr_tms))

            if not summer_started:
                if (sumr_tms[FULL_TERM] and
                        not sumr_tms[A_TERM] and
                        not sumr_tms[B_TERM]):
                    terms.append(_get_future_term_json(next_quarter,
                                                       "full-term",
                                                       sumr_tms))
        else:
            terms.append(_get_future_term_json(next_quarter, ""))

    if next_autumn_sche is not None and len(next_autumn_sche.sections) > 0:
        terms.append(_get_future_term_json(next_autumn_sche.term, ""))
    return terms
Пример #7
0
 def GET(self, request):
     """
     GET returns 200 with the current quarter Textbook
     """
     term = get_current_quarter(request)
     summer_term = ""
     if term.quarter == "summer":
         summer_term = get_current_summer_term(request)
     return self.respond(term.year, term.quarter, summer_term)
Пример #8
0
def _get_registered_future_quarters(request, next_quar_sche, next_autumn_sche):
    """
    Return the list of future quarters that
    has actively enrolled sections

    @param next_quar_sche: ClassSchedule object of a future quarter
    @param next_autumn_quar_sche: ClassSchedule object of the future
           autumn quarter if the next_quar_sche is of summer quarter
    """
    terms = []
    if next_quar_sche is not None and len(next_quar_sche.sections) > 0:
        next_quarter = next_quar_sche.term

        if next_quarter.is_summer_quarter():
            sumr_tms = _get_registered_summer_terms(next_quar_sche.sections)
            # MUWM-3010
            # Filter out A-term and Full-term sections once summer term has
            # started.
            # Filter out B-term courses once B-term has started.
            current = get_current_quarter(request)
            now = get_comparison_date(request)
            summer_started = False
            bterm_started = False

            has_b = sumr_tms[B_TERM]
            if current.is_summer_quarter():
                if now >= current.first_day_quarter:
                    summer_started = True

                if now >= current.bterm_first_date:
                    bterm_started = True

            if not summer_started:
                if sumr_tms[A_TERM] or sumr_tms[FULL_TERM] and has_b:
                    terms.append(
                        _get_future_term_json(next_quarter, "a-term",
                                              sumr_tms))

            if not bterm_started:
                if has_b or sumr_tms[FULL_TERM] and sumr_tms[A_TERM]:
                    terms.append(
                        _get_future_term_json(next_quarter, "b-term",
                                              sumr_tms))

            if not summer_started:
                if (sumr_tms[FULL_TERM] and not sumr_tms[A_TERM]
                        and not sumr_tms[B_TERM]):
                    terms.append(
                        _get_future_term_json(next_quarter, "full-term",
                                              sumr_tms))
        else:
            terms.append(_get_future_term_json(next_quarter, ""))

    if next_autumn_sche is not None and len(next_autumn_sche.sections) > 0:
        terms.append(_get_future_term_json(next_autumn_sche.term, ""))
    return terms
Пример #9
0
 def GET(self, request):
     """
     GET returns 200 with the current quarter course section schedule
     """
     return self.make_http_resp(
         logging.getLogger(__name__),
         Timer(),
         get_current_quarter(request),
         request
         )
Пример #10
0
def get_current_quarter_enrollment(request):
    regid = get_regid_of_current_user()

    timer = Timer()
    id = "%s %s" % ('get enrollment by regid', regid)
    try:
        return get_enrollment_by_regid_and_term(regid,
                                                get_current_quarter(request))
    finally:
        log_resp_time(logger, id, timer)
Пример #11
0
def get_current_quarter_schedule(request):
    """
    Return the actively enrolled sections in the current quarter
    """
    if hasattr(request, "myuw_current_quarter_schedule"):
        return request.myuw_current_quarter_schedule

    schedule = get_schedule_by_term(request, get_current_quarter(request))
    request.myuw_current_quarter_schedule = schedule

    return schedule
Пример #12
0
def get_current_quarter_schedule(request):
    """
    Return the actively enrolled sections in the current quarter
    """
    if hasattr(request, "myuw_current_quarter_schedule"):
        return request.myuw_current_quarter_schedule

    schedule = get_schedule_by_term(get_current_quarter(request))
    request.myuw_current_quarter_schedule = schedule

    return schedule
Пример #13
0
def get_current_quarter_enrollment(request):
    regid = get_regid_of_current_user()

    timer = Timer()
    id = "%s %s" % ("get enrollment by regid", regid)
    try:
        return get_enrollment_by_regid_and_term(regid, get_current_quarter(request))
    except Exception:
        log_exception(logger, id, traceback.format_exc())
    finally:
        log_resp_time(logger, id, timer)
    return None
Пример #14
0
 def GET(self, request):
     """
     GET returns 200 with the current quarter Textbook
     """
     try:
         term = get_current_quarter(request)
         summer_term = ""
         if term.quarter == "summer":
             summer_term = get_current_summer_term(request)
         return self.respond(request, term.year, term.quarter, summer_term)
     except Exception:
         return handle_exception(logger, timer, traceback)
Пример #15
0
def get_current_quarter_enrollment(request):
    regid = get_regid_of_current_user()

    timer = Timer()
    id = "%s %s" % ('get enrollment by regid', regid)
    try:
        return get_enrollment_by_regid_and_term(regid,
                                                get_current_quarter(request))
    finally:
        log_resp_time(logger,
                      id,
                      timer)
Пример #16
0
 def GET(self, request):
     """
     GET returns 200 with the current quarter Textbook
     """
     try:
         term = get_current_quarter(request)
         summer_term = ""
         if term.quarter == "summer":
             summer_term = get_current_summer_term(request)
         return self.respond(request, term.year, term.quarter, summer_term)
     except Exception:
         return handle_exception(logger, timer, traceback)
Пример #17
0
 def GET(self, request):
     """
     GET returns 200 with the current quarter course section schedule
     @return class schedule data in json format
             status 404: no schedule found (not registered)
             status 543: data error
     """
     timer = Timer()
     try:
         return self.make_http_resp(timer, get_current_quarter(request),
                                    request)
     except Exception:
         return handle_exception(logger, timer, traceback)
Пример #18
0
 def GET(self, request):
     """
     GET returns 200 with the current quarter course section schedule
     @return class schedule data in json format
             status 404: no schedule found (not registered)
             status 543: data error
     """
     timer = Timer()
     try:
         return self.make_http_resp(timer,
                                    get_current_quarter(request),
                                    request)
     except Exception:
         return handle_exception(logger, timer, traceback)
Пример #19
0
    def GET(self, request):
        try:
            quarter = get_current_quarter(request)
            plan = get_plan(regid=get_regid_of_current_user(),
                            year=quarter.year,
                            quarter=quarter.quarter,
                            terms=4)

            return HttpResponse(json.dumps(plan.json_data()))
        except Exception as ex:
            # Log the error, but don't have the front end complain
            print ex
            logger.error(ex)
            return HttpResponse('[]')
Пример #20
0
def get_previous_messages(request):
    start_date = get_bod_current_term_class_start(request).date() -\
                 datetime.timedelta(days=10)
    current_date = get_comparison_date(request)
    current_qtr = get_current_quarter(request)

    dates = []
    if current_date >= start_date:
        while start_date <= current_date:
            dates.append(start_date)
            start_date += datetime.timedelta(days=1)

    messages = _get_messages_for_quarter_dates(dates, current_qtr)
    return messages
Пример #21
0
    def test_efs_after_end_of_early_start(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-09-20"
            cur_term = get_current_quarter(now_request)
            self.assertEqual(cur_term.year, 2013)
            self.assertEqual(cur_term.quarter, "autumn")

            user = User.objects.create_user(username='******',
                                            email='*****@*****.**',
                                            password='')

            now_request.user = user
            UserServiceMiddleware().process_request(now_request)
            cur_term = get_current_quarter(now_request)
            fall_efs_schedule = get_schedule_by_term(now_request, cur_term)
            self.assertIsNotNone(fall_efs_schedule)
            self.assertEqual(len(fall_efs_schedule.sections), 1)
Пример #22
0
    def test_efs_after_end_of_early_start(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-09-20"
            cur_term = get_current_quarter(now_request)
            self.assertEqual(cur_term.year, 2013)
            self.assertEqual(cur_term.quarter, "autumn")

            user = User.objects.create_user(username='******',
                                            email='*****@*****.**',
                                            password='')

            now_request.user = user
            UserServiceMiddleware().process_request(now_request)
            cur_term = get_current_quarter(now_request)
            fall_efs_schedule = get_schedule_by_term(now_request, cur_term)
            self.assertIsNotNone(fall_efs_schedule)
            self.assertEqual(len(fall_efs_schedule.sections), 1)
Пример #23
0
def get_previous_messages(request):
    start_date = get_bod_current_term_class_start(request).date() -\
                 datetime.timedelta(days=10)
    current_date = get_comparison_date(request)
    current_qtr = get_current_quarter(request)

    dates = []
    if current_date >= start_date:
        while start_date <= current_date:
            dates.append(start_date)
            start_date += datetime.timedelta(days=1)

    messages = _get_messages_for_quarter_dates(dates, current_qtr)
    return messages
Пример #24
0
    def test_crosslinks_lookup(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            data = get_indexed_data_for_regid(
                "12345678901234567890123456789012")

            now_request = RequestFactory().get("/")
            now_request.session = {}
            term = get_current_quarter(now_request)
            schedule = _get_schedule("12345678901234567890123456789012", term)
            canvas_data_by_course_id = get_indexed_by_decrosslisted(
                data, schedule.sections)

            physics = data['2013,spring,PHYS,121/A']
            self.assertEquals(physics.course_url,
                              'https://canvas.uw.edu/courses/149650')

            train = data['2013,spring,TRAIN,100/A']
            self.assertEquals(train.course_url,
                              'https://canvas.uw.edu/courses/249650')
Пример #25
0
def get_reg_data(now, request):
    """
    now is the second after mid-night
    """
    term_reg_data = {
        "after_start": False,
        "after_summer1_start": False,
        "after_summerA_start": False,
    }
    next_term = get_next_quarter(request)
    get_term_reg_data(now, next_term, term_reg_data)
    # We need to show this term's registration stuff, because
    # the period 2 stretches past the grade submission deadline
    current_term = get_current_quarter(request)
    get_term_reg_data(now, current_term, term_reg_data)
    # We also need to be able to show the term after next, in spring quarter
    term_after_next = get_term_after(next_term)
    get_term_reg_data(now, term_after_next, term_reg_data)
    return term_reg_data
Пример #26
0
def get_reg_data(now, request):
    """
    now is the second after mid-night
    """
    term_reg_data = {
        "after_start": False,
        "after_summer1_start": False,
        "after_summerA_start": False,
        "myplan_peak_load": False
    }
    next_term = get_next_quarter(request)
    get_term_reg_data(now, next_term, term_reg_data)
    # We need to show this term's registration stuff, because
    # the period 2 stretches past the grade submission deadline
    current_term = get_current_quarter(request)
    get_term_reg_data(now, current_term, term_reg_data)
    # We also need to be able to show the term after next, in spring quarter
    term_after_next = get_term_after(next_term)
    get_term_reg_data(now, term_after_next, term_reg_data)
    return term_reg_data
Пример #27
0
    def test_winter_quarter_schedule(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-11-30"
            cur_term = get_current_quarter(now_request)
            self.assertEqual(cur_term.year, 2013)
            self.assertEqual(cur_term.quarter, "autumn")

            next_term = get_next_quarter(now_request)
            self.assertEqual(next_term.year, 2014)
            self.assertEqual(next_term.quarter, "winter")
            self.assertFalse(cur_term == next_term)

            winter2014_sche = _get_schedule(regid, next_term)
            self.assertIsNotNone(winter2014_sche)
            self.assertEqual(len(winter2014_sche.sections), 5)
Пример #28
0
def get_registered_future_quarters(request):
    """
    Return the list of future quarters that
    has actively enrolled sections
    """
    next_quar_sche = get_next_quarter_schedule(request)
    next_autumn_sche = None
    if next_quar_sche and next_quar_sche.term.is_summer_quarter():
        next_autumn_sche = get_next_autumn_quarter_schedule(request)

    # MUWM-3010
    current = get_current_quarter(request)
    if current.is_summer_quarter():
        summer_term = get_current_summer_term(request)
        if is_a_term(summer_term):
            summer = get_current_quarter_schedule(request)
            next_autumn_sche = next_quar_sche
            next_quar_sche = summer

    return _get_registered_future_quarters(request, next_quar_sche,
                                           next_autumn_sche)
Пример #29
0
    def test_winter_quarter_schedule(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS,
                           RESTCLIENTS_PWS_DAO_CLASS=FDAO_PWS):

            regid = "9136CCB8F66711D5BE060004AC494FFE"

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-11-30"
            cur_term = get_current_quarter(now_request)
            self.assertEqual(cur_term.year, 2013)
            self.assertEqual(cur_term.quarter, "autumn")

            next_term = get_next_quarter(now_request)
            self.assertEqual(next_term.year, 2014)
            self.assertEqual(next_term.quarter, "winter")
            self.assertFalse(cur_term == next_term)

            winter2014_sche = _get_schedule(regid, next_term)
            self.assertIsNotNone(winter2014_sche)
            self.assertEqual(len(winter2014_sche.sections), 5)
Пример #30
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)
Пример #31
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)
Пример #32
0
def get_registered_future_quarters(request):
    """
    Return the list of future quarters that
    has actively enrolled sections
    """
    next_quar_sche = get_next_quarter_schedule(request)
    next_autumn_sche = None
    if next_quar_sche and next_quar_sche.term.quarter == 'summer':
        next_autumn_sche = get_next_autumn_quarter_schedule(request)

    # MUWM-3010
    current = get_current_quarter(request)
    if current.quarter == "summer":
        summer_term = get_current_summer_term(request)
        if summer_term == "a-term":
            summer = get_current_quarter_schedule(request)
            next_autumn_sche = next_quar_sche
            next_quar_sche = summer

    return _get_registered_future_quarters(request,
                                           next_quar_sche,
                                           next_autumn_sche)
Пример #33
0
    def filter_too_future_events(self, request, events):
        current = get_current_quarter(request)
        after = get_term_after

        last_date = None
        # MUWM-2522
        # This is intended as a workaround for missing data, but it's proably
        # also good enough if there's an error fetching a term resource
        # against live resources.
        try:
            last = after(after(after(after(current))))
            last_date = last.grade_submission_deadline.date()
        except Exception as ex:
            last_dt = (current.grade_submission_deadline + timedelta(days=365))
            last_date = last_dt.date()

        not_too_future = []
        for event in events:
            start = event.get('dtstart').dt
            if start <= last_date:
                not_too_future.append(event)

        return not_too_future
Пример #34
0
    def filter_too_future_events(self, request, events):
        current = get_current_quarter(request)
        after = get_term_after

        last_date = None
        # MUWM-2522
        # This is intended as a workaround for missing data, but it's proably
        # also good enough if there's an error fetching a term resource
        # against live resources.
        try:
            last = after(after(after(after(current))))
            last_date = last.grade_submission_deadline.date()
        except Exception as ex:
            last_dt = (current.grade_submission_deadline + timedelta(days=365))
            last_date = last_dt.date()

        not_too_future = []
        for event in events:
            start = event.get('dtstart').dt
            if start <= last_date:
                not_too_future.append(event)

        return not_too_future
Пример #35
0
    def test_crosslinks_lookup(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            data = get_indexed_data_for_regid(
                "12345678901234567890123456789012")

            now_request = RequestFactory().get("/")
            now_request.session = {}
            term = get_current_quarter(now_request)
            schedule = _get_schedule("12345678901234567890123456789012", term)
            canvas_data_by_course_id = get_indexed_by_decrosslisted(
                data, schedule.sections)

            physics = data['2013,spring,PHYS,121/A'].course
            self.assertEquals(physics.course_url,
                              'https://canvas.uw.edu/courses/249652')
            self.assertFalse(physics.is_unpublished())

            has_section_a = '2013,spring,TRAIN,100/A' in data
            self.assertTrue(has_section_a)

            train = data['2013,spring,TRAIN,100/A'].course
            self.assertEquals(train.course_url,
                              'https://canvas.uw.edu/courses/249650')
            self.assertTrue(train.is_unpublished())
Пример #36
0
def get_current_message(request):
    current_date = get_comparison_date(request)
    current_qtr = get_current_quarter(request)
    messages = _get_messages_for_quarter_dates([current_date], current_qtr)
    return messages[0] if len(messages) else None
Пример #37
0
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))
Пример #38
0
def get_current_message(request):
    current_date = get_comparison_date(request)
    current_qtr = get_current_quarter(request)
    messages = _get_messages_for_quarter_dates([current_date], current_qtr)
    return messages[0] if len(messages) else None
Пример #39
0
def get_current_quarter_schedule(request):
    """
    Return the actively enrolled sections in the current quarter
    """
    return get_schedule_by_term(get_current_quarter(request))
Пример #40
0
def get_current_message(request):
    current_date = get_comparison_date(request)
    current_qtr = get_current_quarter(request)
    messages = _get_message_for_quarter_date(current_date, current_qtr)
    return messages
Пример #41
0
    def test_current_quarter(self):
        with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS):
            now_request = RequestFactory().get("/")
            now_request.session = {}

            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'spring')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-04-01"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'spring')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-25"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'winter')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-26"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'winter')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-27"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'spring')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-03-31"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'spring')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-24"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'summer')

            # Spring's grade submission deadline is today, so we're not after
            # that, which is why this is an exception to the rule
            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-23"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'spring')

            now_request = RequestFactory().get("/")
            now_request.session = {}
            now_request.session["myuw_override_date"] = "2013-06-18"
            quarter = get_current_quarter(now_request)
            self.assertEquals(quarter.year, 2013)
            self.assertEquals(quarter.quarter, 'spring')
Пример #42
0
def index(request,
          year=None,
          quarter=None,
          summer_term=None):

    timer = Timer()
    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.
        try:
            if not is_student():
                logger.info("%s not a student, redirect to legacy!" % netid)
                return redirect_to_legacy_site()
        except Exception:
            log_exception(logger,
                          '%s is_student' % netid,
                          traceback.format_exc())
            logger.info("%s, redirected to legacy!" % netid)
            return redirect_to_legacy_site()

    else:
        if is_oldmyuw_user():
            return redirect_to_legacy_site()

    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)
    try:
        my_uwemail_forwarding = get_email_forwarding_for_current_user()
        if 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()
    except Exception:
        log_exception(logger,
                      'get_email_forwarding_for_current_user',
                      traceback.format_exc())
        pass

    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!"
        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))