Ticket #15717: 15717.diff

File 15717.diff, 3.2 KB (added by Aymeric Augustin, 14 years ago)
  • django/contrib/databrowse/plugins/calendars.py

     
    66from django.utils.text import capfirst
    77from django.utils.encoding import force_unicode
    88from django.utils.safestring import mark_safe
    9 from django.views.generic import date_based
     9from django.views.generic import dates
    1010from django.utils import datetime_safe
    1111
    1212class CalendarPlugin(DatabrowsePlugin):
     
    6565
    6666    def calendar_view(self, request, field, year=None, month=None, day=None):
    6767        easy_model = EasyModel(self.site, self.model)
    68         queryset = easy_model.get_query_set()
    69         extra_context = {'root_url': self.site.root_url, 'model': easy_model, 'field': field}
     68        root_url = self.site.root_url
     69
     70        class DateViewMixin(object):
     71            allow_empty = False
     72            allow_future = True
     73            date_field = field.name
     74            queryset = easy_model.get_query_set()
     75            def get_context_data(self, **kwargs):
     76                context = super(DateViewMixin, self).get_context_data(**kwargs)
     77                context.update({'root_url': root_url, 'model': easy_model, 'field': field})
     78                return context
     79
    7080        if day is not None:
    71             return date_based.archive_day(request, year, month, day, queryset, field.name,
    72                 template_name='databrowse/calendar_day.html', allow_empty=False, allow_future=True,
    73                 extra_context=extra_context)
     81            class DayView(DateViewMixin, dates.DayArchiveView):
     82                template_name = 'databrowse/calendar_day.html'
     83            return DayView.as_view(year=year, month=month, day=day)(request)
    7484        elif month is not None:
    75             return date_based.archive_month(request, year, month, queryset, field.name,
    76                 template_name='databrowse/calendar_month.html', allow_empty=False, allow_future=True,
    77                 extra_context=extra_context)
     85            class MonthView(DateViewMixin, dates.MonthArchiveView):
     86                template_name = 'databrowse/calendar_month.html'
     87            return MonthView.as_view(year=year, month=month)(request)
    7888        elif year is not None:
    79             return date_based.archive_year(request, year, queryset, field.name,
    80                 template_name='databrowse/calendar_year.html', allow_empty=False, allow_future=True,
    81                 extra_context=extra_context)
     89            class YearView(DateViewMixin, dates.YearArchiveView):
     90                template_name = 'databrowse/calendar_year.html'
     91            return YearView.as_view(year=year)(request)
    8292        else:
    83             return date_based.archive_index(request, queryset, field.name,
    84                 template_name='databrowse/calendar_main.html', allow_empty=True, allow_future=True,
    85                 extra_context=extra_context)
     93            class IndexView(DateViewMixin, dates.ArchiveIndexView):
     94                template_name = 'databrowse/calendar_main.html'
     95            return IndexView.as_view()(request)
     96
    8697        assert False, ('%s, %s, %s, %s' % (field, year, month, day))
Back to Top