def test_normal_fill(self): """ Tests whether an attempt to fill an empty list returns a single filler slot spanning the entire requested range. """ # First, some sanity checks on the test fixture self.assertIsNotNone(Term.of(self.past_time)) self.assertIsNotNone(self.past_time) self.assertIsNotNone(self.future_time) self.assertIsNotNone(self.duration) filled = filler.fill( self.timeslots, self.past_time, self.future_time ) # This should only have filled with one item self.assertEqual(len(filled), 1) filler_slot = filled[0] # ...which should be a Timeslot... self.assertIsInstance(filler_slot, Timeslot) # ... and should take up the entire required range. # The times might be out because filler slots try to set # their start/ends to end/starts of adjacent shows. self.assertTrue(filler_slot.start_time <= self.past_time) self.assertTrue(filler_slot.end_time >= self.future_time)
def test_of_term_end(self): """ Tests whether :method:`of` works correctly on term boundaries. """ for term in self.terms: self.assertIsNone(Term.of(term.end_date))
def term(start_time, duration): """Retrieves a university term that is usable for a filler slot with the given start time and duration (or, more specifically, the pseudo-season thereof). Keyword arguments: start_time -- the start time of the filler timeslot being created, as an aware datetime duration -- the duration of the filler timeslot being created, as a timedelta """ term = Term.of(start_time) if not term: # It's better to return a term that only slightly makes # sense over not returning a term at all term = Term.before(start_time) return term
def test_negative_fill(self): """ Tests whether an attempt to fill an empty list whose start time is after its end time results in an exception. """ # First, some sanity checks on the test fixture self.assertIsNotNone(Term.of(self.past_time)) self.assertIsNotNone(self.past_time) self.assertIsNotNone(self.future_time) self.assertIsNotNone(self.duration) with self.assertRaises(ValueError): filler.fill( self.timeslots, self.future_time, self.past_time )
def schedule_day_from_date(request, day_start): """The day-at-a-glance schedule view, with the day specfied by a date object (including the start time of the schedule). """ this_year, this_week, this_day = day_start.isocalendar() next_start = day_start + timedelta(days=1) next_year, next_week, next_day = next_start.isocalendar() prev_start = day_start - timedelta(days=1) prev_year, prev_week, prev_day = prev_start.isocalendar() term = Term.of(day_start) schedule = None if not term else ScheduleRange.day( day_start, exclude_before_start=False, exclude_after_end=False, exclude_subsuming=False, with_filler_timeslots=True).data return render( request, 'schedule/schedule-day.html', {'day_start': day_start, 'this_year': this_year, 'this_week': this_week, 'next_start': next_start, 'next_year': next_year, 'next_week': next_week, 'next_day': next_day, 'prev_start': prev_start, 'prev_year': prev_year, 'prev_week': prev_week, 'prev_day': prev_day, 'term': term, 'schedule': schedule})
def broadcast_info(request): """ Adds information about whether the radio station is currently broadcasting into the template context, as well as the currently broadcasting shows. """ now = timezone.now() # If any other ways of discerning whether broadcasting is # occurring, add them here! term = Term.of(now) if not term: preterm = Term.before(now) return { 'shows_on_air': day(now), # broadcasting is intended to be true when a schedule is # in play. 'broadcasting': getattr( settings, 'BROADCASTING', (term is not None) ), # transmitting is intended to be a stronger form of # broadcasting, in that it represents times when the station # is technically on air but not necessarily working to a # schedule. 'transmitting': getattr( settings, 'TRANSMITTING', ( term is not None or (preterm is not None and preterm.name.lower() != 'summer') ) ), }
def schedule_week_from_date(request, week_start): """The week-at-a-glance schedule view, with the week specified by a date object denoting its starting day. """ this_year, this_week, this_day = week_start.isocalendar() next_start = week_start + timedelta(weeks=1) next_year, next_week, next_day = next_start.isocalendar() prev_start = week_start - timedelta(weeks=1) prev_year, prev_week, prev_day = prev_start.isocalendar() term = Term.of(week_start) schedule = None if not term else WeekTable.tabulate( ScheduleRange.week( week_start, split_days=True, exclude_before_start=False, exclude_after_end=False, exclude_subsuming=False, with_filler_timeslots=True)) return render( request, 'schedule/schedule-week.html', {'week_start': week_start, 'this_year': this_year, 'this_week': this_week, 'next_start': next_start, 'next_year': next_year, 'next_week': next_week, 'prev_start': prev_start, 'prev_year': prev_year, 'prev_week': prev_week, 'term': term, 'schedule': schedule})