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