Code

Ticket #3542: t3542-r7354.diff

File t3542-r7354.diff, 1.9 KB (added by ramiro, 6 years ago)
Line 
1diff -r a3fc401a5612 django/views/generic/date_based.py
2--- a/django/views/generic/date_based.py        Sun Mar 23 07:14:32 2008 -0300
3+++ b/django/views/generic/date_based.py        Sun Mar 23 22:39:39 2008 -0300
4@@ -10,7 +10,8 @@ def archive_index(request, queryset, dat
5 def archive_index(request, queryset, date_field, num_latest=15,
6         template_name=None, template_loader=loader,
7         extra_context=None, allow_empty=True, context_processors=None,
8-        mimetype=None, allow_future=False, template_object_name='latest'):
9+        mimetype=None, allow_future=False, template_object_name='latest',
10+        date_list_period='year'):
11     """
12     Generic top-level archive of date-based objects.
13 
14@@ -25,7 +26,10 @@ def archive_index(request, queryset, dat
15     model = queryset.model
16     if not allow_future:
17         queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
18-    date_list = queryset.dates(date_field, 'year')[::-1]
19+    if date_list_period == 'month':
20+        date_list = queryset.dates(date_field, 'month')[::-1]
21+    else:
22+        date_list = queryset.dates(date_field, 'year')[::-1]
23     if not date_list and not allow_empty:
24         raise Http404, "No %s available" % model._meta.verbose_name
25 
26diff -r a3fc401a5612 docs/generic_views.txt
27--- a/docs/generic_views.txt    Sun Mar 23 07:14:32 2008 -0300
28+++ b/docs/generic_views.txt    Sun Mar 23 22:39:39 2008 -0300
29@@ -204,6 +204,10 @@ a date in the *future* are not included
30     * **New in Django development version:** ``template_object_name``:
31       Designates the name of the template variable to use in the template
32       context. By default, this is ``'latest'``.
33+
34+    * **New in Django development version:** ``date_list_period``: Specifies
35+      what date period is placed in ``date_list``. Acceptable values are
36+      ``'year'`` and ``'month'``. By default, this is ``'year'``.
37 
38 **Template name:**
39