Example #1
0
    def get_context_data(self, **kwargs):
        context = super(EventDayView, self).get_context_data(**kwargs)

        kw = self.kwargs
        y, m, d = map(int, (kw['year'], kw['month'], kw['day']))
        year, month, day, error = c.clean_year_month_day(y, m, d, self.net)

        if error:
            context['cal_error'] = error

        # Note that we don't prefetch 'cancellations' because they will be
        # prefetched later (in day_display in displays.py)
        all_month_events = self.get_month_events(
            year, month, self.category, self.tag
        )

        self.events = day_display(
            year, month, all_month_events, day
        )

        self.check_for_cancelled_events(d=date(year, month, day))
        context['events'] = self.events

        display_month = MONTHS_ALT[month]
        if isinstance(display_month, six.binary_type):
            display_month = display_month.decode('utf-8')

        context['month'] = display_month
        context['month_num'] = month
        context['year'] = year
        context['day'] = day
        context['month_day_year'] = u"%(month)s %(day)d, %(year)d" % (
            {'month': display_month, 'day': day, 'year': year}
        )

        # for use in the template to build next & prev querystrings
        context['next'], context['prev'] = c.get_next_and_prev(self.net)
        return context
 def test_pos_net(self):
     net = 3
     nxt, prev = get_next_and_prev(net)
     self.assertEqual(nxt, 4)
     self.assertEqual(prev, -2)
 def test_net_zero(self):
     net = 0
     nxt, prev = get_next_and_prev(net)
     self.assertEqual(nxt, 1)
     self.assertEqual(prev, 1)
 def test_neg_net(self):
     net = -3
     nxt, prev = get_next_and_prev(net)
     self.assertEqual(nxt, -2)
     self.assertEqual(prev, 4)