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))
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): """ GET returns 200 with the student account balances of the current user """ timer = Timer() try: profile = get_profile_of_current_user() response = profile.json_data() response['campus'] = get_base_campus(request) response['is_grad_student'] = is_grad_student() try: enrollment = get_current_quarter_enrollment(request) 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()) except Exception: pass log_success_response(logger, timer) return HttpResponse(json.dumps(response)) except Exception: return handle_exception(logger, timer, traceback)
def GET(self, request): """ GET returns 200 with the student account balances of the current user """ timer = Timer() try: profile = get_profile_of_current_user() response = profile.json_data() response['display_name'] = get_display_name_of_current_user() response['campus'] = get_base_campus(request) response['is_grad_student'] = is_grad_student() try: enrollment = get_current_quarter_enrollment(request) 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()) except Exception: pass log_success_response(logger, timer) return HttpResponse(json.dumps(response)) 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): """ GET returns 200 with a list of notices for the current user """ timer = Timer() logger = logging.getLogger(__name__) notice_json = get_json_for_notices( request, get_notices_for_current_user()) log_success_response(logger, timer) return HttpResponse(json.dumps(notice_json))
def GET(self, request): """ GET returns 200 with the uwemail forwarding of the current user """ timer = Timer() try: my_uwemail_forwarding = get_email_forwarding_for_current_user() resp_json = my_uwemail_forwarding.json_data() log_success_response(logger, timer) return HttpResponse(json.dumps(resp_json)) 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): """ GET returns 200 with the HFS account balances of the current user """ timer = Timer() try: balances = get_account_balances_for_current_user() resp_json = balances.json_data(use_custom_date_format=True) log_success_response(logger, timer) return HttpResponse(json.dumps(resp_json)) except Exception: return handle_exception(logger, timer, traceback)
def GET(self, request): """ GET returns 200 with the library account balances of the current user """ timer = Timer() try: myaccount = get_account_info_for_current_user() resp_json = myaccount.json_data( use_abbr_week_month_day_format=True) log_success_response(logger, timer) return HttpResponse(json.dumps(resp_json)) except Exception: return handle_exception(logger, timer, traceback)
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))
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))
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)
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}))
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))
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 GET(self, request): """ GET returns 200 with the registered future quarters of the current user if not registered, returns 200 with the future year & quarter. 543: data error """ timer = Timer() try: try: future_quarters = get_registered_future_quarters(request) except DataFailureException as ex: if ex.status != 404: raise future_quarters = [] resp_data = { "terms": future_quarters } next_non_summer = get_next_non_summer_quarter(request) next_year = next_non_summer.year next_quarter = next_non_summer.quarter has_registration_for_next_term = False for term in future_quarters: if term["quarter"].lower() == next_quarter and\ term["year"] == next_year and\ term["section_count"] > 0: has_registration_for_next_term = True resp_data["next_term_data"] = { "year": next_non_summer.year, "quarter": next_non_summer.quarter.capitalize(), "has_registration": has_registration_for_next_term, } highlight = should_highlight_future_quarters( future_quarters, request) resp_data["highlight_future_quarters"] = highlight log_success_response(logger, timer) return HttpResponse(json.dumps(resp_data)) 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 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))
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 }))
def GET(self, request): """ GET returns 200 with the registered future quarters of the current user if not registered, returns 200 with the future year & quarter. 543: data error """ timer = Timer() try: try: future_quarters = get_registered_future_quarters(request) except DataFailureException as ex: if ex.status != 404: raise future_quarters = [] resp_data = {"terms": future_quarters} next_non_summer = get_next_non_summer_quarter(request) next_year = next_non_summer.year next_quarter = next_non_summer.quarter has_registration_for_next_term = False for term in future_quarters: if term["quarter"].lower() == next_quarter and\ term["year"] == next_year and\ term["section_count"] > 0: has_registration_for_next_term = True resp_data["next_term_data"] = { "year": next_non_summer.year, "quarter": next_non_summer.quarter.capitalize(), "has_registration": has_registration_for_next_term, } highlight = should_highlight_future_quarters( future_quarters, request) resp_data["highlight_future_quarters"] = highlight log_success_response(logger, timer) return HttpResponse(json.dumps(resp_data)) except Exception: return handle_exception(logger, timer, traceback)
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))
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))
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 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(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 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 returns 200 with the registered future quarters of the current user """ future_quarters = get_registered_future_quarters(request) timer = Timer() logger = logging.getLogger(__name__) resp_data = { "terms": future_quarters } next_non_summer = get_next_non_summer_quarter(request) next_year = next_non_summer.year next_quarter = next_non_summer.quarter has_registration_for_next_term = False for term in future_quarters: if ( term["quarter"].lower() == next_quarter and term["year"] == next_year and term["section_count"] > 0 ): has_registration_for_next_term = True resp_data["next_term_data"] = { "year": next_non_summer.year, "quarter": next_non_summer.quarter.capitalize(), "has_registration": has_registration_for_next_term, } highlight = should_highlight_future_quarters(future_quarters, request) resp_data["highlight_future_quarters"] = highlight log_success_response(logger, timer) return HttpResponse(json.dumps(resp_data))
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))