def setUp(self): semester1 = SemesterObjectMother.summer_semester_2015_16() semester1.save() semester2 = SemesterObjectMother.winter_semester_2015_16() semester2.save() friday_to_sunday = ChangedDay( day=date(2015, 10, 16), weekday=common.SUNDAY ) friday_to_sunday.save()
def test_count_changed_days_in_winter_semester(self): semester = Semester.get_semester(datetime(2015, 11, 10)) self.assertNotEqual(semester, None) changed_days = ChangedDay.get_added_days_of_week(semester.semester_beginning, semester.semester_ending) self.assertEqual(len(changed_days), 3)
def test_clean_on_changing_sunday_to_sunday(self): changed_day = ChangedDay(day=datetime(2016, 3, 27), weekday=common.SUNDAY) self.assertRaises(ValidationError, changed_day.clean)
def setUp(self): semester = SemesterObjectMother.winter_semester_2015_16() semester.save() change1 = ChangedDay( day=semester.semester_beginning + timedelta(days=3), weekday=common.SUNDAY ) change1.save() change2 = ChangedDay( day=semester.semester_beginning + timedelta(days=4), weekday=common.SUNDAY ) change2.save() change3 = ChangedDay( day=semester.semester_beginning + timedelta(days=2), weekday=common.SATURDAY ) change3.save()
def get_terms_in_day(cls, date, ajax=False): from apps.schedule.models.term import Term as EventTerm from apps.enrollment.courses.models.semester import Semester, Freeday, ChangedDay from apps.enrollment.courses.models.term import Term rooms = cls.get_in_institute(reservation=True) if not ajax: return rooms # build a dictionary result = {} for room in rooms: if room.number not in result: result[room.number] = { 'id': room.id, 'number': room.number, 'capacity': room.capacity, 'type': room.get_type_display(), 'description': room.description, 'title': room.number, 'terms': [] } # fill event terms terms = EventTerm.objects.filter(day=date, room__in=rooms, event__status='1').select_related( 'room', 'event') def make_dict(start_time, end_time, title): return { 'begin': ':'.join(str(start_time).split(':')[:2]), 'end': ':'.join(str(end_time).split(':')[:2]), 'title': title } for term in terms: result[term.room.number]['terms'].append( make_dict(term.start, term.end, term.event.title)) if not Freeday.is_free(date): # get weekday and semester weekday = ChangedDay.get_day_of_week(date) selected_semester = Semester.get_semester(date) if selected_semester is None: return if selected_semester.lectures_beginning > date or date > selected_semester.lectures_ending: return json.dumps(result) # get courses data course_terms = Term.objects.filter(dayOfWeek=weekday, group__course__semester=selected_semester)\ .select_related('classroom', 'group').prefetch_related('classrooms') # fill courses data for course_term in course_terms: for classroom in course_term.classrooms.all(): if classroom not in rooms: continue result[classroom.number]['terms'].append( make_dict(course_term.start_time, course_term.end_time, course_term.group.course.name)) if course_term.classroom is None: continue result[course_term.classroom.number]['terms'].append( make_dict(course_term.start_time, course_term.end_time, course_term.group.course.name)) return json.dumps(result)