Commit e471bbe2 authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

[1.0.X] Fixed #10458 -- Corrected the `next_month` and `previous_month`...

[1.0.X] Fixed #10458 -- Corrected the `next_month` and `previous_month` context variables provided with the generic month_archive view. The value returned now matches the docstring and the generic views documentation. Thanks to fperetti for the report and initial patch.

Merge of r10556 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10557 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 960d3172
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -144,12 +144,18 @@ def archive_month(request, year, month, queryset, date_field,

    # Calculate the next month, if applicable.
    if allow_future:
        next_month = last_day + datetime.timedelta(days=1)
    elif last_day < datetime.date.today():
        next_month = last_day + datetime.timedelta(days=1)
        next_month = last_day
    elif last_day <= datetime.date.today():
        next_month = last_day
    else:
        next_month = None

    # Calculate the previous month
    if first_day.month == 1:
        previous_month = first_day.replace(year=first_day.year-1,month=12)
    else:
        previous_month = first_day.replace(month=first_day.month-1)

    if not template_name:
        template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower())
    t = template_loader.get_template(template_name)
@@ -157,7 +163,7 @@ def archive_month(request, year, month, queryset, date_field,
        '%s_list' % template_object_name: object_list,
        'month': date,
        'next_month': next_month,
        'previous_month': first_day - datetime.timedelta(days=1),
        'previous_month': previous_month,
    }, context_processors)
    for key, value in extra_context.items():
        if callable(value):
+22 −1
Original line number Diff line number Diff line
# coding: utf-8
from django.test import TestCase
from datetime import datetime
from datetime import datetime, date
from datetime import timedelta
from regressiontests.views.models import Article, Author, DateArticle

@@ -52,6 +52,8 @@ class MonthArchiveTest(TestCase):
        article.save()
        response = self.client.get('/views/date_based/archive_month/2004/02/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['next_month'], date(2004, 3, 1))
        self.assertEqual(response.context['previous_month'], date(2004, 1, 1))

        article.date_created = first_second_of_feb-two_seconds
        article.save()
@@ -62,6 +64,8 @@ class MonthArchiveTest(TestCase):
        article.save()
        response = self.client.get('/views/date_based/archive_month/2004/02/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['next_month'], date(2004, 3, 1))
        self.assertEqual(response.context['previous_month'], date(2004, 1, 1))

        article.date_created = first_second_of_mar
        article.save()
@@ -74,6 +78,8 @@ class MonthArchiveTest(TestCase):
        article2.save()
        response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['next_month'], date(2004, 3, 1))
        self.assertEqual(response.context['previous_month'], date(2004, 1, 1))

        article2.date_created = (first_second_of_feb-two_seconds).date()
        article2.save()
@@ -84,12 +90,27 @@ class MonthArchiveTest(TestCase):
        article2.save()
        response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['next_month'], date(2004, 3, 1))
        self.assertEqual(response.context['previous_month'], date(2004, 1, 1))

        article2.date_created = first_second_of_mar.date()
        article2.save()
        response = self.client.get('/views/date_based/datefield/archive_month/2004/02/')
        self.assertEqual(response.status_code, 404)

        now = datetime.now()
        prev_month = now.date().replace(day=1)
        if prev_month.month == 11:
            prev_month = prev_month.replace(year=prev_month.year-1, month=12)
        else:
            prev_month = prev_month.replace(month=prev_month.month-1)
        article2.date_created = now
        article2.save()
        response = self.client.get('/views/date_based/datefield/archive_month/%s/' % now.strftime('%Y/%m'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context['next_month'], None)
        self.assertEqual(response.context['previous_month'], prev_month)

class DayArchiveTests(TestCase):

    def test_year_month_day_format(self):