Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15717 -- Updated databrowse to use class-based generic date vi…

…ews. Thanks to aaugustin for the report and draft patch

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16002 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 74f7ad32a51c7bf9e013f1865e4039ac07fd71b9 1 parent e6a5e41
@freakboy3742 freakboy3742 authored
Showing with 74 additions and 16 deletions.
  1. +74 −16 django/contrib/databrowse/plugins/calendars.py
View
90 django/contrib/databrowse/plugins/calendars.py
@@ -6,9 +6,43 @@
from django.utils.text import capfirst
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
-from django.views.generic import date_based
+from django.views.generic import dates
from django.utils import datetime_safe
+
+class DateViewMixin(object):
+ allow_empty = False
+ allow_future = True
+ root_url = None
+ model = None
+ field = None
+
+ def get_context_data(self, **kwargs):
+ context = super(DateViewMixin, self).get_context_data(**kwargs)
+ context.update({
+ 'root_url': self.root_url,
+ 'model': self.model,
+ 'field': self.field
+ })
+ return context
+
+
+class DayView(DateViewMixin, dates.DayArchiveView):
+ template_name = 'databrowse/calendar_day.html'
+
+
+class MonthView(DateViewMixin, dates.MonthArchiveView):
+ template_name = 'databrowse/calendar_month.html'
+
+
+class YearView(DateViewMixin, dates.YearArchiveView):
+ template_name = 'databrowse/calendar_year.html'
+
+
+class IndexView(DateViewMixin, dates.ArchiveIndexView):
+ template_name = 'databrowse/calendar_main.html'
+
+
class CalendarPlugin(DatabrowsePlugin):
def __init__(self, field_names=None):
self.field_names = field_names
@@ -61,26 +95,50 @@ def homepage_view(self, request):
easy_model = EasyModel(self.site, self.model)
field_list = self.fields.values()
field_list.sort(key=lambda k:k.verbose_name)
- return render_to_response('databrowse/calendar_homepage.html', {'root_url': self.site.root_url, 'model': easy_model, 'field_list': field_list})
+ return render_to_response('databrowse/calendar_homepage.html', {
+ 'root_url': self.site.root_url,
+ 'model': easy_model,
+ 'field_list': field_list
+ })
def calendar_view(self, request, field, year=None, month=None, day=None):
easy_model = EasyModel(self.site, self.model)
- queryset = easy_model.get_query_set()
- extra_context = {'root_url': self.site.root_url, 'model': easy_model, 'field': field}
+ root_url = self.site.root_url
+
if day is not None:
- return date_based.archive_day(request, year, month, day, queryset, field.name,
- template_name='databrowse/calendar_day.html', allow_empty=False, allow_future=True,
- extra_context=extra_context)
+ return DayView.as_view(
+ year=year, month=month, day=day,
+ date_field=field.name,
+ queryset=easy_model.get_query_set(),
+ root_url=root_url,
+ model=easy_model,
+ field=field
+ )(request)
elif month is not None:
- return date_based.archive_month(request, year, month, queryset, field.name,
- template_name='databrowse/calendar_month.html', allow_empty=False, allow_future=True,
- extra_context=extra_context)
+ return MonthView.as_view(
+ year=year, month=month,
+ date_field=field.name,
+ queryset=easy_model.get_query_set(),
+ root_url=root_url,
+ model=easy_model,
+ field=field
+ )(request)
elif year is not None:
- return date_based.archive_year(request, year, queryset, field.name,
- template_name='databrowse/calendar_year.html', allow_empty=False, allow_future=True,
- extra_context=extra_context)
+ return YearView.as_view(
+ year=year,
+ date_field=field.name,
+ queryset=easy_model.get_query_set(),
+ root_url=root_url,
+ model=easy_model,
+ field=field
+ )(request)
else:
- return date_based.archive_index(request, queryset, field.name,
- template_name='databrowse/calendar_main.html', allow_empty=True, allow_future=True,
- extra_context=extra_context)
+ return IndexView.as_view(
+ date_field=field.name,
+ queryset=easy_model.get_query_set(),
+ root_url=root_url,
+ model=easy_model,
+ field=field
+ )(request)
+
assert False, ('%s, %s, %s, %s' % (field, year, month, day))
Please sign in to comment.
Something went wrong with that request. Please try again.