Code

Ticket #3274: date_list_for_archive_month.diff

File date_list_for_archive_month.diff, 1.8 KB (added by paolo <paolo@…>, 7 years ago)

date_list_for_archive_month

Line 
1Index: django/views/generic/date_based.py
2===================================================================
3--- django/views/generic/date_based.py  (revision 4300)
4+++ django/views/generic/date_based.py  (working copy)
5@@ -103,6 +103,8 @@
6 
7     Templates: ``<app_label>/<model_name>_archive_month.html``
8     Context:
9+        date_list
10+            List of days in this month with objects
11         month:
12             (date) this month
13         next_month:
14@@ -133,7 +135,8 @@
15     if last_day >= now.date() and not allow_future:
16         lookup_kwargs['%s__lte' % date_field] = now
17     object_list = queryset.filter(**lookup_kwargs)
18-    if not object_list and not allow_empty:
19+    date_list = object_list.dates(date_field, 'day')
20+    if not date_list and not allow_empty:
21         raise Http404
22 
23     # Calculate the next month, if applicable.
24@@ -148,6 +151,7 @@
25         template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower())
26     t = template_loader.get_template(template_name)
27     c = RequestContext(request, {
28+        'date_list': date_list,
29         '%s_list' % template_object_name: object_list,
30         'month': date,
31         'next_month': next_month,
32Index: docs/generic_views.txt
33===================================================================
34--- docs/generic_views.txt      (revision 4290)
35+++ docs/generic_views.txt      (working copy)
36@@ -381,6 +381,10 @@
37 
38 In addition to ``extra_context``, the template's context will be:
39 
40+    * ``date_list``: A list of ``datetime.date`` objects representing all
41+      days that have objects available in the given month, according to
42+      ``queryset``, in ascending order.
43+
44     * ``month``: A ``datetime.date`` object representing the given month.
45 
46     * ``next_month``: A ``datetime.date`` object representing the first day of