Fixed #15717 -- Updated databrowse to use class-based generic date views. 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
This commit is contained in:
parent
e6a5e41cdf
commit
74f7ad32a5
|
@ -6,9 +6,43 @@ from django.shortcuts import render_to_response
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
from django.utils.safestring import mark_safe
|
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
|
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):
|
class CalendarPlugin(DatabrowsePlugin):
|
||||||
def __init__(self, field_names=None):
|
def __init__(self, field_names=None):
|
||||||
self.field_names = field_names
|
self.field_names = field_names
|
||||||
|
@ -61,26 +95,50 @@ class CalendarPlugin(DatabrowsePlugin):
|
||||||
easy_model = EasyModel(self.site, self.model)
|
easy_model = EasyModel(self.site, self.model)
|
||||||
field_list = self.fields.values()
|
field_list = self.fields.values()
|
||||||
field_list.sort(key=lambda k:k.verbose_name)
|
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):
|
def calendar_view(self, request, field, year=None, month=None, day=None):
|
||||||
easy_model = EasyModel(self.site, self.model)
|
easy_model = EasyModel(self.site, self.model)
|
||||||
queryset = easy_model.get_query_set()
|
root_url = self.site.root_url
|
||||||
extra_context = {'root_url': self.site.root_url, 'model': easy_model, 'field': field}
|
|
||||||
if day is not None:
|
if day is not None:
|
||||||
return date_based.archive_day(request, year, month, day, queryset, field.name,
|
return DayView.as_view(
|
||||||
template_name='databrowse/calendar_day.html', allow_empty=False, allow_future=True,
|
year=year, month=month, day=day,
|
||||||
extra_context=extra_context)
|
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:
|
elif month is not None:
|
||||||
return date_based.archive_month(request, year, month, queryset, field.name,
|
return MonthView.as_view(
|
||||||
template_name='databrowse/calendar_month.html', allow_empty=False, allow_future=True,
|
year=year, month=month,
|
||||||
extra_context=extra_context)
|
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:
|
elif year is not None:
|
||||||
return date_based.archive_year(request, year, queryset, field.name,
|
return YearView.as_view(
|
||||||
template_name='databrowse/calendar_year.html', allow_empty=False, allow_future=True,
|
year=year,
|
||||||
extra_context=extra_context)
|
date_field=field.name,
|
||||||
|
queryset=easy_model.get_query_set(),
|
||||||
|
root_url=root_url,
|
||||||
|
model=easy_model,
|
||||||
|
field=field
|
||||||
|
)(request)
|
||||||
else:
|
else:
|
||||||
return date_based.archive_index(request, queryset, field.name,
|
return IndexView.as_view(
|
||||||
template_name='databrowse/calendar_main.html', allow_empty=True, allow_future=True,
|
date_field=field.name,
|
||||||
extra_context=extra_context)
|
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))
|
assert False, ('%s, %s, %s, %s' % (field, year, month, day))
|
||||||
|
|
Loading…
Reference in New Issue