Exemple #1
0
 def getNextEvent(self): # next occurrence of this happening
     if self.repeats('NEVER'):
         return self.start_date
     elif self.end_repeat > timezone.now().date():
         next = get_next_event([self], timezone.now())
         pvm = date(next[0], next[1], next[2])
         return pvm
     # in case repetition has ended, show nothing
     return None
Exemple #2
0
    def test_next_event_start_end_diff_month_monthly_repeat(self):
        create_event(
            start_date=(2014, 2, 28),
            end_date=(2014, 3, 1),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="MONTHLY",
        )
        event = Event.objects.all()

        date = datetime.datetime(2014, 3, 1)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 3, 1))

        date = datetime.datetime(2014, 5, 5)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 5, 28))
Exemple #3
0
    def test_next_event_single(self):
        """Test a non-chunk event"""
        create_event(
            start_date=(2014, 3, 1),
            end_date=(2014, 3, 1),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="WEEKLY",
        )
        event = Event.objects.all()

        date = datetime.datetime(2014, 3, 5)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 3, 8))

        date = datetime.datetime(2014, 4, 9)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 4, 12))
Exemple #4
0
    def test_next_event_over_same_day(self):
        """Test that an event over for the day doesn't show up."""
        create_event(
            start_date=(2015, 5, 1, 10),
            end_date=(2015, 5, 1, 13),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="WEEKDAY",
        )
        event = Event.objects.all()

        date = datetime.datetime(2015, 5, 4, 9)  # before
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 5, 4))
        date = date.replace(hour=12)  # during
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 5, 5))
        date = date.replace(hour=14)  # after
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 5, 5))
Exemple #5
0
    def test_next_event_weekly_repeat(self):
        create_event(
            start_date=(2014, 2, 15),
            end_date=(2014, 2, 16),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="WEEKLY",
        )
        event = Event.objects.all()
        # use date_dicts, and put the for loop into its own func (like i did
        # with check_dates)
        # date_dicts = [
        #    {datetime.datetime(2014, 2, 19): (2014, 2, 22)},
        #    {datetime.datetime(2014, 3, 13): (2014, 3, 15)},
        #    {datetime.datetime(2014, 4, 5): (2014, 4, 5)},
        #    {datetime.datetime(2015, 4, 5): (2015, 4, 5)}
        # ]

        # for date_dict in date_dicts:
        #    for d in date_dict.items():
        #        z, x = d[0], d[1]
        #        y, m, d = get_next_event(event, z)
        #        self.assertEqual((y, m, d), x)

        date = datetime.datetime(2014, 2, 19)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 2, 22))

        date = datetime.datetime(2014, 3, 13)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 3, 15))

        date = datetime.datetime(2014, 4, 5)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 4, 5))

        date = datetime.datetime(2015, 4, 5)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 4, 5))
Exemple #6
0
    def test_next_event_biweekly_repeat(self):
        create_event(
            start_date=(2014, 3, 1),
            end_date=(2014, 3, 4),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="BIWEEKLY",
        )
        event = Event.objects.all()

        date = datetime.datetime(2014, 3, 13)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 3, 15))

        date = datetime.datetime(2014, 4, 12)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 4, 12))

        date = datetime.datetime(2014, 3, 1)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 3, 1))
Exemple #7
0
    def test_next_event_weekday_repeat_starts_on_non_weekday(self):
        create_event(
            start_date=(2014, 6, 1),
            end_date=(2014, 6, 1),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="WEEKDAY",
        )
        event = Event.objects.all()

        date = datetime.datetime(2014, 5, 7)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2014, 6, 2))
Exemple #8
0
    def test_next_event_with_time(self):
        """
        Test that an event over for today, but not scheduled to
        even appear for today, shows up correctly.
        """
        create_event(
            start_date=(2015, 5, 22, 10),
            end_date=(2015, 5, 22, 13),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="WEEKLY",
        )
        event = Event.objects.all()

        date = datetime.datetime(2015, 5, 28, 9)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 5, 29))
        date = date.replace(hour=12)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 5, 29))
        date = date.replace(hour=14)
        y, m, d = get_next_event(event, date)
        self.assertEqual((y, m, d), (2015, 5, 29))
Exemple #9
0
 def test_next_event_bugfix2(self):
     """
     This tests a bug that was discovered on June 6, 2014 that
     had the wrong next event being shown for a yearly repeating event.
     """
     create_event(
         start_date=(2014, 3, 15),
         end_date=(2014, 3, 15),
         created_by=self.user,
         title="The Event",
         description="This is an event. Enjoy.",
         repeat="YEARLY",
     )
     event = Event.objects.all()
     date = datetime.datetime(2014, 6, 6)
     y, m, d = get_next_event(event, date)
     self.assertEqual((y, m, d), (2015, 3, 15))
Exemple #10
0
 def test_next_event_bugfix(self):
     """
     This tests a bug that was discovered on May 28, 2014 that
     had the wrong next event being shown.
     """
     create_event(
         start_date=(2014, 5, 26),
         end_date=(2014, 5, 26),
         created_by=self.user,
         title="The Event",
         description="This is an event. Enjoy.",
         repeat="WEEKLY",
     )
     event = Event.objects.all()
     date = datetime.datetime(2014, 5, 29)
     y, m, d = get_next_event(event, date)
     self.assertEqual((y, m, d), (2014, 6, 2))
Exemple #11
0
    def get_context_data(self, **kwargs):
        now = c.get_now()
        context = super(EventDetailView, self).get_context_data(**kwargs)
        e = self.object

        for choice in Event.REPEAT_CHOICES:
            if choice[0] == e.repeat:
                context['repeat'] = choice[1]

        context['cncl_days'] = self.get_cncl_days()

        event = [e]  # event needs to be an iterable, see get_next_event()
        if not e.repeats('NEVER'):  # event is ongoing; get next occurrence
            if e.will_occur(now):
                year, month, day = get_next_event(event, now)
                next_event = date(year, month, day)
                context['next_event'] = date(year, month, day)
                context['next_or_prev_cncl'] = self.check_cncl(next_event)
            else:  # event is finished repeating; get last occurrence
                end = e.end_repeat
                last_event = end
                if e.repeats('WEEKDAY'):
                    year, month, day = c.check_weekday(
                        end.year, end.month, end.day, reverse=True
                    )
                    last_event = date(year, month, day)
                context['last_event'] = last_event
                context['next_or_prev_cncl'] = self.check_cncl(last_event)
        else:
            if e.is_chunk():
                # list of days for single-day event chunk
                context['event_days'] = (  # list comp
                    (e.l_start_date + timedelta(days=x))
                    for x in range(e.start_end_diff + 1)
                )
            else:
                # let template know if this single-day, non-repeating event is
                # cancelled
                context['this_cncl'] = self.check_cncl(e.l_start_date.date())
        return context
Exemple #12
0
    def test_next_event_yearly_repeat(self):
        create_event(
            start_date=(2014, 5, 3),
            end_date=(2014, 5, 6),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="YEARLY",
        )
        event = Event.objects.all()

        dates = [
            [(2014, 4, 7), (2014, 5, 3)],
            [(2014, 5, 1), (2014, 5, 3)],
            [(2014, 5, 7), (2015, 5, 3)],
            [(2015, 1, 7), (2015, 5, 3)],
            [(2017, 5, 5), (2017, 5, 5)],
        ]
        for item in dates:
            now = datetime.datetime(*item[0])
            y, m, d = get_next_event(event, now)
            self.assertEqual((y, m, d), item[1])
Exemple #13
0
    def test_next_event_monthly_repeat(self):
        create_event(
            start_date=(2014, 4, 1),
            end_date=(2014, 4, 3),
            created_by=self.user,
            title="The Event",
            description="This is an event. Enjoy.",
            repeat="MONTHLY",
        )
        event = Event.objects.all()

        dates = [
            [(2014, 4, 7), (2014, 5, 1)],
            [(2014, 5, 20), (2014, 6, 1)],
            [(2014, 6, 2), (2014, 6, 2)],
            [(2014, 4, 3), (2014, 4, 3)],
            [(2014, 4, 4), (2014, 5, 1)],
            [(2014, 2, 2), (2014, 4, 1)],
        ]
        for item in dates:
            now = datetime.datetime(*item[0])
            y, m, d = get_next_event(event, now)
            self.assertEqual((y, m, d), item[1])