def test_comparison_date(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): now_request = RequestFactory().get("/") now_request.session = {} no_override = get_comparison_date(now_request) self.assertEquals(no_override.year, 2013) self.assertEquals(no_override.month, 4) self.assertEquals(no_override.day, 15) now_request.session["myuw_override_date"] = "2014-01-01" no_override = get_comparison_date(now_request) self.assertEquals(no_override.year, 2014) self.assertEquals(no_override.month, 1) self.assertEquals(no_override.day, 1)
def apply_showhide(request, notices): """ Some financial aid notices have additional show/hide logic depending on the open/close dates of the notice. This function will apply the show/hide logic on each notice, update the notice atttibutes accordingly. """ if notices is None: return None today = get_comparison_date(request) local_tz = timezone.get_current_timezone() now = local_tz.localize( datetime(today.year, today.month, today.day, 0, 0, 1)).astimezone(pytz.utc) for notice in notices: if notice.notice_category != "StudentFinAid": continue if equals_myuwid(notice, "StudentFinAid_AidPriorityDate"): # not critical after the first week and # before last two weeks if is_after_eof_days_after_open(now, notice, 15) and\ is_before_bof_days_before_close(now, notice, 15): notice.is_critical = False return notices
def get_card_visibilty_date_values(request=None): now = get_comparison_date(request) after_midnight = datetime(now.year, now.month, now.day, 0, 0, 1) values = get_values_by_date(after_midnight, request) set_js_overrides(request, values) return values
def save_seen_registration_obj(user, request, term): year = term["year"] quarter = term["quarter"] summer_term = _get_summer_term(term) qset = SeenRegistration.objects.filter( user=user, year=year, quarter=quarter, summer_term=summer_term, ) if len(qset) > 1: logger.warning( "%s with user=%s, year=%d, quarter=%s, summer_term=%s" % ("Multiple Objects", user.uwnetid, year, quarter, summer_term)) # MUWM-3137, remove bad data qset.delete() now_datetime = _get_actual_now(get_comparison_date(request)) model, created = SeenRegistration.objects.get_or_create( user=user, year=year, quarter=quarter, summer_term=summer_term, defaults={'first_seen_date': now_datetime}) return model, created, now_datetime, summer_term
def in_show_grades_period(term, request): """ return true if it is within the grades display window - before the 1st day of next quarter """ comparison_date = get_comparison_date(request) next_term = get_term_after(term) return comparison_date < next_term.first_day_quarter
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
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
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 filter_non_current(self, request, events): comparison_date = get_comparison_date(request) last_date = comparison_date + timedelta(days=7*4) ok_overlaps = {} round1 = [] for event in events: if event.get('dtstart').dt <= last_date: # The comparison date is the first date of the event in # the ideal event window (now -> 4 weeks from now) start = event.get('dtstart').dt if start < comparison_date: start = comparison_date date_string = self.format_native_datetime(start) # We only want to show events from the first 3 days that # overlap though if date_string not in ok_overlaps: if len(ok_overlaps.keys()) >= CURRENT_LIST_MAX_DAYS: # We've hit our 4th day - # return the values we've collected return round1 else: # Track the new date ok_overlaps[date_string] = True # This event is in that first 3 matching days round1.append(event) else: start = event.get('dtstart') date_string = self.format_datetime(start) # There's an event outside of 4 weeks. 3 things can happen: # 1) we already have events, and the event's start date isn't # in the ok_overlaps lookup # - return what we have, we're outside the window # 2) we don't have any events # - this is the first event, and it's outside the ideal # window. we want to show all events from this day # 3) we have events, and today's date is in ok_overlaps. # - this is not the first event of the day, but it is a day # of events we want to include. if len(round1) == 0: # Case 2 ok_overlaps[date_string] = True if date_string in ok_overlaps: # Case 3, or a continuation of case 2 round1.append(event) else: # Case 1 return round1 # If all of our events were in the first 3 days... return round1
def filter_past_events(self, request, events): comparison_date = get_comparison_date(request) non_past = [] for event in events: # Events' end dates are midnight of the next day - not what we want # muwm-2489 end_date = self.event_end_date(event) if end_date >= comparison_date: non_past.append(event) return non_past
def filter_non_current(self, request, events): comparison_date = get_comparison_date(request) last_date = comparison_date + timedelta(days=7 * 4) ok_overlaps = {} round1 = [] for event in events: if event.get('dtstart').dt <= last_date: # The comparison date is the first date of the event in # the ideal event window (now -> 4 weeks from now) start = event.get('dtstart').dt if start < comparison_date: start = comparison_date date_string = self.format_native_datetime(start) # We only want to show events from the first 3 days that # overlap though if date_string not in ok_overlaps: if len(ok_overlaps.keys()) >= CURRENT_LIST_MAX_DAYS: # We've hit our 4th day - # return the values we've collected return round1 else: # Track the new date ok_overlaps[date_string] = True # This event is in that first 3 matching days round1.append(event) else: start = event.get('dtstart') date_string = self.format_datetime(start) # There's an event outside of 4 weeks. 3 things can happen: # 1) we already have events, and the event's start date isn't # in the ok_overlaps lookup # - return what we have, we're outside the window # 2) we don't have any events # - this is the first event, and it's outside the ideal # window. we want to show all events from this day # 3) we have events, and today's date is in ok_overlaps. # - this is not the first event of the day, but it is a day # of events we want to include. if len(round1) == 0: # Case 2 ok_overlaps[date_string] = True if date_string in ok_overlaps: # Case 3, or a continuation of case 2 round1.append(event) else: # Case 1 return round1 # If all of our events were in the first 3 days... return round1
def json_for_evaluation(request, evaluations, section_summer_term): if evaluations is None: return None local_tz = timezone.get_current_timezone() today = get_comparison_date(request) now = local_tz.localize( datetime(today.year, today.month, today.day, 0, 0, 1)) # the start date of the default show window show_date = get_bof_7d_before_last_instruction(request) on_dt = local_tz.localize( datetime(show_date.year, show_date.month, show_date.day, 0, 0, 0)) # the end date of the default show window hide_date = get_eof_term(request, True) off_dt = local_tz.localize( datetime(hide_date.year, hide_date.month, hide_date.day, 0, 0, 0)) if now < on_dt or now > off_dt: return None pws = PWS() json_data = [] for evaluation in evaluations: if term_matched(request, section_summer_term): if now < evaluation.eval_open_date or\ now >= evaluation.eval_close_date: continue if evaluation.eval_close_date < off_dt: off_dt = evaluation.eval_close_date json_item = {'instructors': [], 'url': evaluation.eval_url, 'is_multi_instr': len(evaluation.instructor_ids) > 1} for eid in evaluation.instructor_ids: instructor_json = {} instructor = pws.get_person_by_employee_id(eid) instructor_json['instructor_name'] = instructor.display_name instructor_json['instructor_title'] = instructor.title1 json_item['instructors'].append(instructor_json) json_data.append(json_item) # althrough each item has its own close date, we # only take one - the earliest. if len(json_data) > 0: return {'evals': json_data, 'close_date': off_dt.isoformat()} return None
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
def add_date_term_info(request, context): actual_now = get_default_date() used_now = get_comparison_date(request) context["actual_now_date"] = str(actual_now) context["effective_now_date"] = str(used_now) context["is_using_mock_data"] = is_using_file_dao() try: actual_term = get_term_by_date(actual_now) context["actual_now_term_year"] = actual_term.year context["actual_now_term_quarter"] = actual_term.quarter except Exception as ex: pass try: used_term = get_term_by_date(used_now) context["effective_now_term_year"] = used_term.year context["effective_now_term_quarter"] = used_term.quarter except Exception as ex: pass
def get_schedule_by_term(request, term): """ Return the actively enrolled sections for the current user in the given term/quarter """ # 2016 approach for MUWM-3390/3391 # If we're in the EFS period, include the sections. Otherwise, # exclude them. schedule = _get_schedule(get_regid_of_current_user(), term) comparison_date = get_comparison_date(request) included_sections = [] for section in schedule.sections: if EARLY_FALL_START != section.institute_name: included_sections.append(section) else: end_date = section.end_date if end_date >= comparison_date: included_sections.append(section) schedule.sections = included_sections return schedule
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
def api_request(request): current_date = get_comparison_date(request) current_date = datetime.combine(current_date, timezone.now().time()) current_date = pytz.utc.localize(current_date) calendar_ids = get_calendars_for_current_user(request) return get_events(calendar_ids, current_date)
def get_now(request): now = get_comparison_date(request) return datetime(now.year, now.month, now.day, 0, 0, 1)
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