def test_list_view_calendar_starts_different_day(self): """Test that the calendar can start on different days.""" # start on Monday cal = displays.month_display(2014, 3, [], 0, 0, '') s = '</a></th></tr><tr><th class="mon">Mon</th><th class="tue"' self.assertIn(s, self.clean_whitespace(cal)) # start on Sunday cal = displays.month_display(2014, 3, [], 6, 0, '') s = '</a></th></tr><tr><th class="sun">Sun</th><th class="mon"' self.assertIn(s, self.clean_whitespace(cal))
def test_list_view_calendar_starts_different_day(self): """Test that the calendar can start on different days.""" # start on Monday cal = displays.month_display( 2014, 3, [], 0, 0, '' ) s = '</a></th></tr>\n<tr><th class="mon">Mon</th><th class="tue"' self.assertIn(s, cal) # start on Sunday cal = displays.month_display( 2014, 3, [], 6, 0, '' ) s = '</a></th></tr>\n<tr><th class="sun">Sun</th><th class="mon"' self.assertIn(s, cal)
def show_calendar(context, req=None, mini=False, inherit_context=False): req = req or context.get('request', None) if not (req and hasattr(req, 'path') and hasattr(req, 'META')): raise TemplateSyntaxError(r"{% show_calendar %} should be called with HttpRequest instance as first argument or it should be available as `request` variable in template context") now = get_now() net, category, tag = get_net_category_tag(req) year = now.year month = now.month + net year, month, error = clean_year_month(year, month, None) prefetch = {'loc': True, 'cncl': True} if mini: prefetch['loc'] = False # locations aren't displayed on mini calendar all_month_events = list(Event.objects.all_month_events( year, month, category, tag, **prefetch )) all_month_events.sort(key=lambda x: x.l_start_date.hour) qs = req.META['QUERY_STRING'] if qs: # get any querystrings that are not next/prev qs = get_qs(qs) if not inherit_context: context = {} return month_display( year, month, all_month_events, start_day, net, qs, mini=mini, request=req, context=context, )
def show_calendar(context, req=None, mini=False, inherit_context=False): req = req or context.get('request', None) if not (req and hasattr(req, 'path') and hasattr(req, 'META')): raise TemplateSyntaxError(r"{% show_calendar %} should be called with HttpRequest instance as first argument " r"or it should be available as `request` variable in template context") now = get_now() net, category, tag = get_net_category_tag(req) year = now.year month = now.month + net year, month, error = clean_year_month(year, month, None) prefetch = {'loc': True, 'cncl': True} if mini: prefetch['loc'] = False # locations aren't displayed on mini calendar all_month_events = list(Event.objects.all_month_events( year, month, category, tag, **prefetch )) all_month_events.sort(key=lambda x: x.l_start_date.hour) qs = req.META['QUERY_STRING'] if qs: # get any querystrings that are not next/prev qs = get_qs(qs) if not inherit_context: context = {} return month_display( year, month, all_month_events, start_day, net, qs, mini=mini, request=req, context=context, )
def get_context_data(self, **kwargs): context = super(EventMonthView, self).get_context_data(**kwargs) qs = self.request.META['QUERY_STRING'] year, month, error = self.get_year_and_month(self.net, qs) mini = True if 'cal_mini=true' in qs else False # get any querystrings that are not next/prev/year/month if qs: qs = c.get_qs(qs) # add a dict containing the year, month, and month name to the context current = dict(year=year, month_num=month, month=month_name[month][:3]) context['current'] = current display_month = month_name[month] if isinstance(display_month, six.binary_type): display_month = display_month.decode('utf-8') context['month_and_year'] = u"%(month)s, %(year)d" % ({ 'month': display_month, 'year': year }) if error: # send any year/month errors context['cal_error'] = error # List enables sorting. As far as I can tell, .order_by() can't be used # here because we need it ordered by l_start_date.hour (simply ordering # by start_date won't work). The only alternative I've found is to use # extra(), but this would likely require different statements for # different databases... all_month_events = list( self.get_month_events(year, month, self.category, self.tag, loc=True, cncl=True)) all_month_events.sort(key=lambda x: x.l_start_date.hour) start_day = getattr(settings, "CALENDAR_START_DAY", 0) context['calendar'] = month_display(year, month, all_month_events, start_day, self.net, qs, mini) context['show_events'] = False if getattr(settings, "CALENDAR_SHOW_LIST", False): context['show_events'] = True context['events'] = c.order_events(all_month_events, d=True) \ if self.request.is_ajax() else c.order_events(all_month_events) return context
def get_context_data(self, **kwargs): context = super(EventMonthView, self).get_context_data(**kwargs) qs = self.request.META['QUERY_STRING'] year, month, error = self.get_year_and_month(self.net, qs) mini = True if 'cal_mini=true' in qs else False # get any querystrings that are not next/prev/year/month if qs: qs = c.get_qs(qs) # add a dict containing the year, month, and month name to the context current = dict( year=year, month_num=month, month=MONTHS_ALT[month][:3] ) context['current'] = current display_month = MONTHS_ALT[month] if isinstance(display_month, six.binary_type): display_month = display_month.decode('utf-8') context['month_and_year'] = u"%(month)s, %(year)d" % ( {'month': display_month, 'year': year} ) if error: # send any year/month errors context['cal_error'] = error # List enables sorting. As far as I can tell, .order_by() can't be used # here because we need it ordered by l_start_date.hour (simply ordering # by start_date won't work). The only alternative I've found is to use # extra(), but this would likely require different statements for # different databases... all_month_events = list(self.get_month_events( year, month, self.category, self.tag, loc=True, cncl=True )) all_month_events.sort(key=lambda x: x.l_start_date.hour) start_day = getattr(settings, "CALENDAR_START_DAY", 0) context['calendar'] = month_display( year, month, all_month_events, start_day, self.net, qs, mini, request=self.request, ) context['show_events'] = False if getattr(settings, "CALENDAR_SHOW_LIST", False): context['show_events'] = True context['events'] = c.order_events(all_month_events, d=True) \ if self.request.is_ajax() else c.order_events(all_month_events) return context
def show_calendar(req, mini=False): now = get_now() net, category, tag = get_net_category_tag(req) year = now.year month = now.month + net year, month, error = clean_year_month(year, month, None) prefetch = {'loc': True, 'cncl': True} if mini: prefetch['loc'] = False # locations aren't displayed on mini calendar all_month_events = list(Event.objects.all_month_events( year, month, category, tag, **prefetch )) all_month_events.sort(key=lambda x: x.l_start_date.hour) qs = req.META['QUERY_STRING'] if qs: # get any querystrings that are not next/prev qs = get_qs(qs) return month_display( year, month, all_month_events, start_day, net, qs, mini=mini )