Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
r12195 - in django/trunk: django/views/generic docs/ref tests/regressiontests/views/te sts/generic
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
nore...@djangoproject.com  
View profile  
 More options Jan 10 2010, 2:52 pm
From: nore...@djangoproject.com
Date: Sun, 10 Jan 2010 13:52:17 -0600 (CST)
Local: Sun, Jan 10 2010 2:52 pm
Subject: [Changeset] r12195 - in django/trunk: django/views/generic docs/ref tests/regressiontests/views/tests/generi c
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »