def test_is_past(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): quarter = get_quarter(2013, "autumn") now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2014-01-01" self.assertTrue(is_past(quarter, now_request))
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 """ timer = Timer() smr_term = "" if summer_term and len(summer_term) > 1: smr_term = summer_term.title() request_term = get_quarter(year, quarter) if not request_term: return HttpResponse(status=404) if is_past(request_term, request): if not in_show_grades_period(request_term, request): return HttpResponse(status=410) return self.make_http_resp( logging.getLogger(__name__), timer, request_term, request, smr_term)
def should_highlight_future_quarters(schedule, request): should_highlight = False # MUWM-2373 now = get_comparison_date(request) for term in schedule: summer_term = "F" if term["summer_term"] == "a-term": summer_term = "A" if term["summer_term"] == "b-term": summer_term = "B" sr_get_or_create = SeenRegistration.objects.get_or_create model, created = sr_get_or_create(user=get_user_model(), year=term["year"], quarter=term["quarter"], summer_term=summer_term, ) # Want to make sure that we have a full day, not just today/tomorrow actual_now = timezone.now() now_datetime = datetime(now.year, now.month, now.day, actual_now.hour, actual_now.minute, actual_now.second, tzinfo=actual_now.tzinfo) if created: model.first_seen_date = now_datetime model.save() else: # MUWM-3009 if summer_term == "B": term_obj = get_quarter(term["year"], "summer") bterm_start = term_obj.bterm_first_date bterm_start_dt = datetime(bterm_start.year, bterm_start.month, bterm_start.day, 0, 0, 0, tzinfo=actual_now.tzinfo) new_highlight = bterm_start_dt - timedelta(days=8) seen_before = model.first_seen_date < bterm_start_dt is_after = now_datetime > new_highlight if seen_before and is_after: model.first_seen_date = now_datetime model.save() days_diff = (now_datetime - model.first_seen_date).days # XXX - this needs to be changed when we can set a time in the override if days_diff < 1.02: should_highlight = True return should_highlight
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))