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 GET(self, request, year, quarter, summer_term=None): """ GET returns 200 with course section schedule details of the given year, quarter. Return the course sections of full term and matched term if a specific summer-term is given @return class schedule data in json format status 404: no schedule found (not registered) status 543: data error """ timer = Timer() try: smr_term = "" if summer_term and len(summer_term) > 1: smr_term = summer_term.title() request_term = get_specific_term(year, quarter) if is_past(request_term, request): if not in_show_grades_period(request_term, request): log_msg(logger, timer, "Future term has pasted") return invalid_future_term() return self.make_http_resp(timer, request_term, request, smr_term) except Exception: return handle_exception(logger, timer, traceback)
def GET(self, request, year, quarter): timer = Timer() try: no_myplan_access = during_myplan_peak_load( get_comparison_datetime(request), request) if no_myplan_access: log_msg(logger, timer, "No MyPlan access during their peak load, abort!") return HttpResponse('[]') plan = get_plan(regid=get_regid_of_current_user(), year=year, quarter=quarter.lower(), terms=1) base_json = plan.json_data() has_ready_courses = False has_unready_courses = False ready_count = 0 unready_count = 0 has_sections = False for course in base_json["terms"][0]["courses"]: if course["registrations_available"]: has_ready_courses = True ready_count = ready_count + 1 for section in course["sections"]: has_sections = True curriculum = course["curriculum_abbr"].upper() section_id = section["section_id"].upper() label = "%s,%s,%s,%s/%s" % (year, quarter.lower(), curriculum, course["course_number"], section_id ) sws_section = get_section_by_label(label) section["section_data"] = sws_section.json_data() else: if len(course["sections"]): has_sections = True has_unready_courses = True unready_count = unready_count + 1 base_json["terms"][0]["has_ready_courses"] = has_ready_courses base_json["terms"][0]["has_unready_courses"] = has_unready_courses base_json["terms"][0]["ready_count"] = ready_count base_json["terms"][0]["unready_count"] = unready_count base_json["terms"][0]["has_sections"] = has_sections log_success_response(logger, timer) return HttpResponse(json.dumps(base_json)) except Exception: log_err(logger, timer, traceback.format_exc()) return HttpResponse('[]')
def GET(self, request, year, quarter): timer = Timer() try: no_myplan_access = during_myplan_peak_load( get_comparison_datetime(request), request) if no_myplan_access: log_msg(logger, timer, "No MyPlan access during their peak load, abort!") return HttpResponse('[]') plan = get_plan(regid=get_regid_of_current_user(), year=year, quarter=quarter.lower(), terms=1) base_json = plan.json_data() has_ready_courses = False has_unready_courses = False ready_count = 0 unready_count = 0 has_sections = False for course in base_json["terms"][0]["courses"]: if course["registrations_available"]: has_ready_courses = True ready_count = ready_count + 1 for section in course["sections"]: has_sections = True curriculum = course["curriculum_abbr"].upper() section_id = section["section_id"].upper() label = "%s,%s,%s,%s/%s" % (year, quarter.lower( ), curriculum, course["course_number"], section_id) sws_section = get_section_by_label(label) section["section_data"] = sws_section.json_data() else: if len(course["sections"]): has_sections = True has_unready_courses = True unready_count = unready_count + 1 base_json["terms"][0]["has_ready_courses"] = has_ready_courses base_json["terms"][0]["has_unready_courses"] = has_unready_courses base_json["terms"][0]["ready_count"] = ready_count base_json["terms"][0]["unready_count"] = unready_count base_json["terms"][0]["has_sections"] = has_sections log_success_response(logger, timer) return HttpResponse(json.dumps(base_json)) except Exception: log_err(logger, timer, traceback.format_exc()) return HttpResponse('[]')
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)
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)