Django

Code

Changeset 3039

Show
Ignore:
Timestamp:
05/31/06 23:21:26 (2 years ago)
Author:
adrian
Message:

Fixed #697 -- Added make_object_list parameter to archive_year generic view. Thanks, jhf@hex.no

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/generic/date_based.py

    r3022 r3039  
    4646def archive_year(request, year, queryset, date_field, template_name=None, 
    4747        template_loader=loader, extra_context={}, allow_empty=False, 
    48         context_processors=None, mimetype=None): 
     48        context_processors=None, template_object_name='object', mimetype=None, 
     49        make_object_list=False): 
    4950    """ 
    5051    Generic yearly archive view. 
     
    5657        year 
    5758            This year 
     59        object_list 
     60            List of objects published in the given month 
     61            (Only available if make_object_list argument is True) 
    5862    """ 
    5963    model = queryset.model 
     
    6872    if not date_list and not allow_empty: 
    6973        raise Http404 
     74    if make_object_list: 
     75        object_list = queryset.filter(**lookup_kwargs).order_by(date_field) 
     76    else: 
     77        object_list = [] 
    7078    if not template_name: 
    7179        template_name = "%s/%s_archive_year.html" % (model._meta.app_label, model._meta.object_name.lower()) 
     
    7482        'date_list': date_list, 
    7583        'year': year, 
     84        '%s_list' % template_object_name: object_list, 
    7685    }, context_processors) 
    7786    for key, value in extra_context.items(): 
  • django/trunk/docs/generic_views.txt

    r3022 r3039  
    251251      the view's template. See the `RequestContext docs`_. 
    252252 
     253    * ``template_object_name``:  Designates the name of the template variable 
     254       to use in the template context. By default, this is ``'object'``. The 
     255       view will append ``'_list'`` to the value of this parameter in 
     256       determining the variable's name. 
     257 
     258    * ``make_object_list``: A boolean specifying whether to retrieve the full 
     259      list of objects for this year and pass those to the template. If ``True``, 
     260      this list of objects will be made available to the template as 
     261      ``object_list``. (The name ``object_list`` may be different; see the docs 
     262      for ``object_list`` in the "Template context" section below.) By default, 
     263      this is ``False``. 
     264 
    253265    * ``mimetype``: The MIME type to use for the resulting document. Defaults 
    254266      to the value of the ``DEFAULT_MIME_TYPE`` setting. 
     
    266278      months that have objects available in the given year, according to 
    267279      ``queryset``, in ascending order. 
     280 
    268281    * ``year``: The given year, as a four-character string. 
     282 
     283    * ``object_list``: If the ``make_object_list`` parameter is ``True``, this 
     284      will be set to a list of objects available for the given year, ordered by 
     285      the date field. This variable's name depends on the 
     286      ``template_object_name`` parameter, which is ``'object'`` by default. If 
     287      ``template_object_name`` is ``'foo'``, this variable's name will be 
     288      ``foo_list``. 
     289 
     290      If ``make_object_list`` is ``False``, ``object_list`` will be passed to 
     291      the template as an empty list. 
    269292 
    270293``django.views.generic.date_based.archive_month``