Browse files

Fixed #697 -- Added make_object_list parameter to archive_year generi…

…c view. Thanks,

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 5c5d60a commit 5077f9ceafa650cc2af7be6de55769f45eb7939e @adrianholovaty adrianholovaty committed Jun 1, 2006
Showing with 33 additions and 1 deletion.
  1. +10 −1 django/views/generic/
  2. +23 −0 docs/generic_views.txt
@@ -45,7 +45,8 @@ def archive_index(request, queryset, date_field, num_latest=15,
def archive_year(request, year, queryset, date_field, template_name=None,
template_loader=loader, extra_context={}, allow_empty=False,
- context_processors=None, mimetype=None):
+ context_processors=None, template_object_name='object', mimetype=None,
+ make_object_list=False):
Generic yearly archive view.
@@ -55,6 +56,9 @@ def archive_year(request, year, queryset, date_field, template_name=None,
List of months in this year with objects
This year
+ object_list
+ List of objects published in the given month
+ (Only available if make_object_list argument is True)
model = queryset.model
now =
@@ -67,12 +71,17 @@ def archive_year(request, year, queryset, date_field, template_name=None,
date_list = queryset.filter(**lookup_kwargs).dates(date_field, 'month')
if not date_list and not allow_empty:
raise Http404
+ if make_object_list:
+ object_list = queryset.filter(**lookup_kwargs).order_by(date_field)
+ else:
+ object_list = []
if not template_name:
template_name = "%s/%s_archive_year.html" % (model._meta.app_label, model._meta.object_name.lower())
t = template_loader.get_template(template_name)
c = RequestContext(request, {
'date_list': date_list,
'year': year,
+ '%s_list' % template_object_name: object_list,
}, context_processors)
for key, value in extra_context.items():
if callable(value):
@@ -250,6 +250,18 @@ with a date in the *future* are not displayed.
* ``context_processors``: A list of template-context processors to apply to
the view's template. See the `RequestContext docs`_.
+ * ``template_object_name``: Designates the name of the template variable
+ to use in the template context. By default, this is ``'object'``. The
+ view will append ``'_list'`` to the value of this parameter in
+ determining the variable's name.
+ * ``make_object_list``: A boolean specifying whether to retrieve the full
+ list of objects for this year and pass those to the template. If ``True``,
+ this list of objects will be made available to the template as
+ ``object_list``. (The name ``object_list`` may be different; see the docs
+ for ``object_list`` in the "Template context" section below.) By default,
+ this is ``False``.
* ``mimetype``: The MIME type to use for the resulting document. Defaults
to the value of the ``DEFAULT_MIME_TYPE`` setting.
@@ -265,8 +277,19 @@ In addition to ``extra_context``, the template's context will be:
* ``date_list``: A list of ```` objects representing all
months that have objects available in the given year, according to
``queryset``, in ascending order.
* ``year``: The given year, as a four-character string.
+ * ``object_list``: If the ``make_object_list`` parameter is ``True``, this
+ will be set to a list of objects available for the given year, ordered by
+ the date field. This variable's name depends on the
+ ``template_object_name`` parameter, which is ``'object'`` by default. If
+ ``template_object_name`` is ``'foo'``, this variable's name will be
+ ``foo_list``.
+ If ``make_object_list`` is ``False``, ``object_list`` will be passed to
+ the template as an empty list.

0 comments on commit 5077f9c

Please sign in to comment.