Added allow_empty hook to archive_index date-based generic view.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1510 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0c5cf18e1d
commit
bf0f6ec3b4
|
@ -8,7 +8,7 @@ import datetime, time
|
|||
|
||||
def archive_index(request, app_label, module_name, date_field, num_latest=15,
|
||||
template_name=None, template_loader=template_loader,
|
||||
extra_lookup_kwargs={}, extra_context={}):
|
||||
extra_lookup_kwargs={}, extra_context={}, allow_empty=False):
|
||||
"""
|
||||
Generic top-level archive of date-based objects.
|
||||
|
||||
|
@ -23,10 +23,10 @@ def archive_index(request, app_label, module_name, date_field, num_latest=15,
|
|||
lookup_kwargs = {'%s__lte' % date_field: datetime.datetime.now()}
|
||||
lookup_kwargs.update(extra_lookup_kwargs)
|
||||
date_list = getattr(mod, "get_%s_list" % date_field)('year', **lookup_kwargs)[::-1]
|
||||
if not date_list:
|
||||
if not date_list and not allow_empty:
|
||||
raise Http404("No %s.%s available" % (app_label, module_name))
|
||||
|
||||
if num_latest:
|
||||
if date_list and num_latest:
|
||||
lookup_kwargs.update({
|
||||
'limit': num_latest,
|
||||
'order_by': ('-' + date_field,),
|
||||
|
@ -140,7 +140,7 @@ def archive_month(request, year, month, app_label, module_name, date_field,
|
|||
|
||||
def archive_day(request, year, month, day, app_label, module_name, date_field,
|
||||
month_format='%b', day_format='%d', template_name=None,
|
||||
template_loader=template_loader, extra_lookup_kwargs={},
|
||||
template_loader=template_loader, extra_lookup_kwargs={},
|
||||
extra_context={}, allow_empty=False):
|
||||
"""
|
||||
Generic daily archive view.
|
||||
|
@ -204,7 +204,7 @@ def archive_today(request, **kwargs):
|
|||
def object_detail(request, year, month, day, app_label, module_name, date_field,
|
||||
month_format='%b', day_format='%d', object_id=None, slug=None,
|
||||
slug_field=None, template_name=None, template_name_field=None,
|
||||
template_loader=template_loader, extra_lookup_kwargs={},
|
||||
template_loader=template_loader, extra_lookup_kwargs={},
|
||||
extra_context={}):
|
||||
"""
|
||||
Generic detail view from year/month/day/slug or year/month/day/id structure.
|
||||
|
|
|
@ -135,9 +135,21 @@ arguments:
|
|||
The date-based generic functions are:
|
||||
|
||||
``archive_index``
|
||||
A top-level index page showing the "latest" objects. Has an optional
|
||||
argument, ``num_latest``, which is the number of items to display on the
|
||||
page (defaults to 15).
|
||||
A top-level index page showing the "latest" objects.
|
||||
|
||||
Takes the following optional arguments:
|
||||
|
||||
======================= =================================================
|
||||
Argument Description
|
||||
======================= =================================================
|
||||
``num_latest`` The number of items to display on the page.
|
||||
Defaults to 15.
|
||||
|
||||
``allow_empty`` **New in Django development version.**
|
||||
If ``False`` and there are no objects to display,
|
||||
the view will raise a 404 instead of displaying
|
||||
an empty index page. ``False`` is default.
|
||||
======================= =================================================
|
||||
|
||||
Uses the template ``app_label/module_name_archive`` by default.
|
||||
|
||||
|
|
Loading…
Reference in New Issue