def test_events_between(self): event1 = ScheduledEventFactory.create(title='1') event2 = ScheduledEventFactory.create(title='2', date=date(2012, 6, 12)) event3 = ScheduledEventFactory.create(title='3', date=date(2012, 6, 19)) early_event = ScheduledEventFactory.create(title='early', date=date(2012, 6, 11)) late_event = ScheduledEventFactory.create(title='late', date=date(2012, 6, 20)) events = ScheduledEvent.events_between(date(2012, 6, 12), date(2012, 6, 19)) self.assertEqual(list(events), [event2, event1, event3, ]) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [early_event, event2, event1, ]) events = ScheduledEvent.events_between(date(2012, 6, 12), date(2012, 6, 20)) self.assertEqual(list(events), [event2, event1, event3, late_event, ])
def __init__(self, thedate=None): self.date = thedate if not self.date: self.date = date.today() self.monday, self.sunday = get_week_bounds(self.date) regular_events = RegularEvent.objects.all().order_by('start_time') scheduled = ScheduledEvent.events_between(self.monday, self.sunday) self.calendar_entries = [] self.events_to_schedule = False for i in range(0, 7): this_date = self.monday + timedelta(days=i) day_schedule = DaySchedule(i, this_date, regular_events, scheduled) self.calendar_entries.append(day_schedule) if [s for s in day_schedule.regular_events if s.autoschedule]: self.events_to_schedule = True
def test_events_between_multi_day_during(self): event1 = ScheduledEventFactory.create(end_date=date(2012, 6, 16)) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [event1, ])
def get_context_data(self, **kwargs): def is_too_far_in_the_future(year): return year > date.today().year + 2 ctx = super(DiaryPrintableView, self).get_context_data( **kwargs ) if is_too_far_in_the_future(int(self.kwargs['year'])): raise Http404 bounds = self.get_date_bounds() nextmonth = bounds[1] + timedelta(days=1) ctx['startdate'] = bounds[0] ctx['events'] = ScheduledEvent.events_between(*bounds) if not is_too_far_in_the_future(nextmonth.year): ctx['nextmonth'] = nextmonth ctx['nexturl'] = reverse( 'kanisa_public_diary_printable', args=[ '%d' % nextmonth.year, '%02d' % nextmonth.month ] ) return ctx
def test_events_between_multi_day_during(self): event1 = ScheduledEventFactory.create(end_date=date(2012, 6, 16)) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [ event1, ])
def test_events_between_multi_day_after(self): event1 = ScheduledEventFactory.create(end_date=date(2012, 6, 20)) # This one starts after the range we care about ScheduledEventFactory.create(date=date(2012, 6, 16), end_date=date(2012, 6, 20)) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [event1, ])
def test_events_between_multi_days_before(self): event1 = ScheduledEventFactory.create(date=date(2012, 6, 10), end_date=date(2012, 6, 16)) # This one ends before the range we care about ScheduledEventFactory.create(date=date(2012, 6, 9), end_date=date(2012, 6, 10)) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [event1, ])
def test_events_between_multi_day_after(self): event1 = ScheduledEventFactory.create(end_date=date(2012, 6, 20)) # This one starts after the range we care about ScheduledEventFactory.create(date=date(2012, 6, 16), end_date=date(2012, 6, 20)) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [ event1, ])
def test_events_between_multi_days_before(self): event1 = ScheduledEventFactory.create(date=date(2012, 6, 10), end_date=date(2012, 6, 16)) # This one ends before the range we care about ScheduledEventFactory.create(date=date(2012, 6, 9), end_date=date(2012, 6, 10)) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [ event1, ])
def test_events_between(self): event1 = ScheduledEventFactory.create(title='1') event2 = ScheduledEventFactory.create(title='2', date=date(2012, 6, 12)) event3 = ScheduledEventFactory.create(title='3', date=date(2012, 6, 19)) early_event = ScheduledEventFactory.create(title='early', date=date(2012, 6, 11)) late_event = ScheduledEventFactory.create(title='late', date=date(2012, 6, 20)) events = ScheduledEvent.events_between(date(2012, 6, 12), date(2012, 6, 19)) self.assertEqual(list(events), [ event2, event1, event3, ]) events = ScheduledEvent.events_between(date(2012, 6, 11), date(2012, 6, 15)) self.assertEqual(list(events), [ early_event, event2, event1, ]) events = ScheduledEvent.events_between(date(2012, 6, 12), date(2012, 6, 20)) self.assertEqual(list(events), [ event2, event1, event3, late_event, ])
def get_this_week(containing=None): monday, sunday = get_week_bounds(containing) events = ScheduledEvent.events_between(monday, sunday) thisweek = [] for i in range(0, 7): thedate = monday + timedelta(days=i) thisweek.append( (thedate, [e for e in events if event_covers_date(e, thedate)])) return { 'previous_week': monday - timedelta(days=1), 'events': thisweek, 'next_week': sunday + timedelta(days=1) }
def get_this_week(containing=None): monday, sunday = get_week_bounds(containing) events = ScheduledEvent.events_between(monday, sunday) thisweek = [] for i in range(0, 7): thedate = monday + timedelta(days=i) thisweek.append((thedate, [e for e in events if event_covers_date(e, thedate)])) return { 'previous_week': monday - timedelta(days=1), 'events': thisweek, 'next_week': sunday + timedelta(days=1) }