def test_eof_term(self): with self.settings(RESTCLIENTS_SWS_DAO_CLASS=FDAO_SWS): now_request = RequestFactory().get("/") now_request.session = {} now_request.session["myuw_override_date"] = "2013-03-10" self.assertEqual(get_eof_term(now_request), datetime(2013, 3, 27, 0, 0, 0)) now_request.session = {} now_request.session["myuw_override_date"] = "2013-07-10" self.assertEqual(get_eof_term(now_request, True), datetime(2013, 7, 25, 0, 0, 0)) now_request.session = {} now_request.session["myuw_override_date"] = "2013-08-10" self.assertEqual(get_eof_term(now_request), datetime(2013, 8, 28, 0, 0, 0))
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