Author: kmtracey
Date: 2010-01-10 13:52:17 -0600 (Sun, 10 Jan 2010)
New Revision: 12195

Modified:
   django/trunk/django/views/generic/date_based.py
   django/trunk/docs/ref/generic-views.txt
   django/trunk/tests/regressiontests/views/tests/generic/date_based.py
Log:
Fixed: 3274: Added date_list context variable to the archive_month generic 
view, consistent with archive_index and archive_year.  Thanks Sean Brant.


Modified: django/trunk/django/views/generic/date_based.py
===================================================================
--- django/trunk/django/views/generic/date_based.py     2010-01-10 19:23:42 UTC 
(rev 12194)
+++ django/trunk/django/views/generic/date_based.py     2010-01-10 19:52:17 UTC 
(rev 12195)
@@ -105,6 +105,8 @@
 
     Templates: ``<app_label>/<model_name>_archive_month.html``
     Context:
+        date_list:
+            List of days in this month with objects
         month:
             (date) this month
         next_month:
@@ -139,6 +141,7 @@
     if last_day >= now.date() and not allow_future:
         lookup_kwargs['%s__lte' % date_field] = now
     object_list = queryset.filter(**lookup_kwargs)
+    date_list = object_list.dates(date_field, 'day')
     if not object_list and not allow_empty:
         raise Http404
 
@@ -160,6 +163,7 @@
         template_name = "%s/%s_archive_month.html" % (model._meta.app_label, 
model._meta.object_name.lower())
     t = template_loader.get_template(template_name)
     c = RequestContext(request, {
+        'date_list': date_list,
         '%s_list' % template_object_name: object_list,
         'month': date,
         'next_month': next_month,

Modified: django/trunk/docs/ref/generic-views.txt
===================================================================
--- django/trunk/docs/ref/generic-views.txt     2010-01-10 19:23:42 UTC (rev 
12194)
+++ django/trunk/docs/ref/generic-views.txt     2010-01-10 19:52:17 UTC (rev 
12195)
@@ -369,8 +369,15 @@
 
 **Template context:**
 
+.. versionadded:: 1.2
+   The inclusion of ``date_list`` in the template's context is new.
+
 In addition to ``extra_context``, the template's context will be:
 
+    * ``date_list``: A list of ``datetime.date`` objects representing all
+      days that have objects available in the given month, according to
+      ``queryset``, in ascending order.    
+
     * ``month``: A ``datetime.date`` object representing the given month.
 
     * ``next_month``: A ``datetime.date`` object representing the first day of

Modified: django/trunk/tests/regressiontests/views/tests/generic/date_based.py
===================================================================
--- django/trunk/tests/regressiontests/views/tests/generic/date_based.py        
2010-01-10 19:23:42 UTC (rev 12194)
+++ django/trunk/tests/regressiontests/views/tests/generic/date_based.py        
2010-01-10 19:52:17 UTC (rev 12195)
@@ -110,6 +110,22 @@
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.context['next_month'], None)
         self.assertEqual(response.context['previous_month'], prev_month)
+        
+    def test_archive_month_date_list(self):
+        author = Author(name="John Smith")
+        author.save()
+        date1 = datetime(2010, 1, 1, 0, 0, 0)
+        date2 = datetime(2010, 1, 2, 0, 0, 0)
+        Article.objects.create(title='example1', author=author, 
date_created=date1)
+        Article.objects.create(title='example2', author=author, 
date_created=date2)
+        response = self.client.get('/views/date_based/archive_month/2010/1/')
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(len(response.context['date_list']), 2)
+        self.assertEqual(response.context['date_list'][0], date1)
+        # Checks that the same date is not included more than once in the list
+        Article.objects.create(title='example2', author=author, 
date_created=date2)
+        response = self.client.get('/views/date_based/archive_month/2010/1/')
+        self.assertEqual(len(response.context['date_list']), 2)
 
 class DayArchiveTests(TestCase):
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.


Reply via email to