Fixed #1229 -- Added allow_empty argument to archive_year and archive_month date-based generic views

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2337 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-02-18 20:13:46 +00:00
parent e029c9f7f8
commit 73ddfd8bd2
2 changed files with 11 additions and 4 deletions

View File

@ -51,7 +51,7 @@ def archive_index(request, app_label, module_name, date_field, num_latest=15,
def archive_year(request, year, app_label, module_name, date_field, def archive_year(request, year, app_label, module_name, date_field,
template_name=None, template_loader=loader, extra_lookup_kwargs={}, template_name=None, template_loader=loader, extra_lookup_kwargs={},
extra_context={}, context_processors=None): extra_context={}, allow_empty=False, context_processors=None):
""" """
Generic yearly archive view. Generic yearly archive view.
@ -70,7 +70,7 @@ def archive_year(request, year, app_label, module_name, date_field,
lookup_kwargs['%s__lte' % date_field] = now lookup_kwargs['%s__lte' % date_field] = now
lookup_kwargs.update(extra_lookup_kwargs) lookup_kwargs.update(extra_lookup_kwargs)
date_list = getattr(mod, "get_%s_list" % date_field)('month', **lookup_kwargs) date_list = getattr(mod, "get_%s_list" % date_field)('month', **lookup_kwargs)
if not date_list: if not date_list and not allow_empty:
raise Http404 raise Http404
if not template_name: if not template_name:
template_name = "%s/%s_archive_year" % (app_label, module_name) template_name = "%s/%s_archive_year" % (app_label, module_name)
@ -88,7 +88,8 @@ def archive_year(request, year, app_label, module_name, date_field,
def archive_month(request, year, month, app_label, module_name, date_field, def archive_month(request, year, month, app_label, module_name, date_field,
month_format='%b', template_name=None, template_loader=loader, month_format='%b', template_name=None, template_loader=loader,
extra_lookup_kwargs={}, extra_context={}, context_processors=None): extra_lookup_kwargs={}, extra_context={}, allow_empty=False,
context_processors=None):
""" """
Generic monthly archive view. Generic monthly archive view.
@ -122,7 +123,7 @@ def archive_month(request, year, month, app_label, module_name, date_field,
lookup_kwargs['%s__lte' % date_field] = now lookup_kwargs['%s__lte' % date_field] = now
lookup_kwargs.update(extra_lookup_kwargs) lookup_kwargs.update(extra_lookup_kwargs)
object_list = mod.get_list(**lookup_kwargs) object_list = mod.get_list(**lookup_kwargs)
if not object_list: if not object_list and not allow_empty:
raise Http404 raise Http404
if not template_name: if not template_name:
template_name = "%s/%s_archive_month" % (app_label, module_name) template_name = "%s/%s_archive_month" % (app_label, module_name)

View File

@ -168,6 +168,9 @@ The date-based generic functions are:
Yearly archive. Requires that the ``year`` argument be present in the URL Yearly archive. Requires that the ``year`` argument be present in the URL
pattern. pattern.
**New in Django development version:** Takes an optional ``allow_empty``
parameter, as ``archive_index``.
Uses the template ``app_label/module_name_archive_year`` by default. Uses the template ``app_label/module_name_archive_year`` by default.
Has the following template context: Has the following template context:
@ -187,6 +190,9 @@ The date-based generic functions are:
default, which is a three-letter month abbreviation. To change it to use default, which is a three-letter month abbreviation. To change it to use
numbers, use ``"%m"``. numbers, use ``"%m"``.
**New in Django development version:** Takes an optional ``allow_empty``
parameter, as ``archive_index``.
Uses the template ``app_label/module_name_archive_month`` by default. Uses the template ``app_label/module_name_archive_month`` by default.
Has the following template context: Has the following template context: