Django

Code

Ticket #3542: t3542-r7354.diff

File t3542-r7354.diff, 1.9 kB (added by ramiro, 3 months ago)
  • a/django/views/generic/date_based.py

    old new  
    1010def archive_index(request, queryset, date_field, num_latest=15, 
    1111        template_name=None, template_loader=loader, 
    1212        extra_context=None, allow_empty=True, context_processors=None, 
    13         mimetype=None, allow_future=False, template_object_name='latest'): 
     13        mimetype=None, allow_future=False, template_object_name='latest', 
     14        date_list_period='year'): 
    1415    """ 
    1516    Generic top-level archive of date-based objects. 
    1617 
     
    2526    model = queryset.model 
    2627    if not allow_future: 
    2728        queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()}) 
    28     date_list = queryset.dates(date_field, 'year')[::-1] 
     29    if date_list_period == 'month': 
     30        date_list = queryset.dates(date_field, 'month')[::-1] 
     31    else: 
     32        date_list = queryset.dates(date_field, 'year')[::-1] 
    2933    if not date_list and not allow_empty: 
    3034        raise Http404, "No %s available" % model._meta.verbose_name 
    3135 
  • a/docs/generic_views.txt

    old new  
    204204    * **New in Django development version:** ``template_object_name``: 
    205205      Designates the name of the template variable to use in the template 
    206206      context. By default, this is ``'latest'``. 
     207 
     208    * **New in Django development version:** ``date_list_period``: Specifies 
     209      what date period is placed in ``date_list``. Acceptable values are  
     210      ``'year'`` and ``'month'``. By default, this is ``'year'``.  
    207211 
    208212**Template name:** 
    209213