Ticket #17192: next_day_17192.diff

File next_day_17192.diff, 3.4 KB (added by Piotr Banaszkiewicz, 13 years ago)
  • django/views/generic/dates.py

    diff --git a/django/views/generic/dates.py b/django/views/generic/dates.py
    index 5f5f959..f8a35ca 100644
    a b def _get_next_prev_month(generic_view, naive_result, is_previous, use_first_day)  
    584584        result = result.replace(day=1)
    585585
    586586    # Check against future dates.
    587     if result and (allow_future or result < datetime.date.today()):
     587    if result and (allow_future or result <= datetime.date.today()):
    588588        return result
    589589    else:
    590590        return None
  • tests/regressiontests/generic_views/dates.py

    diff --git a/tests/regressiontests/generic_views/dates.py b/tests/regressiontests/generic_views/dates.py
    index 652f66b..f7168ca 100644
    a b class DayArchiveViewTests(TestCase):  
    337337        res = self.client.get('/dates/books/%s/' % urlbit)
    338338        self.assertEqual(res.status_code, 404)
    339339
     340        # specific case for the day before current day (==yesterday)
     341        today = datetime.date.today()
     342        yesterday = today - datetime.timedelta(days=1)
     343        urlbit2 = yesterday.strftime("%Y/%b/%d").lower()
     344        b2 = Book.objects.create(name="Djangonauts: psychoanalisys of the insane",
     345                pages=512, pubdate=yesterday)
     346        b3 = Book.objects.create(name="Djangonauts: psychoanalisys of the insane",
     347                pages=1024, pubdate=today)
     348        res = self.client.get('/dates/books/%s/' % urlbit2)
     349        self.assertEqual(res.context['next_day'], datetime.date.today())
     350        # remove those crazy books so that the tests below don't fail
     351        b2.delete()
     352        b3.delete()
     353
    340354        # allow_future = True, valid future month
    341355        res = self.client.get('/dates/books/%s/allow_future/' % urlbit)
    342356        self.assertEqual(res.status_code, 200)
  • tests/regressiontests/views/tests/generic/date_based.py

    diff --git a/tests/regressiontests/views/tests/generic/date_based.py b/tests/regressiontests/views/tests/generic/date_based.py
    index 96555e5..6b9a83a 100644
    a b class MonthArchiveTest(TestCase):  
    130130        self.assertEqual(response.status_code, 200)
    131131        self.assertEqual(response.context['next_month'], None)
    132132        self.assertEqual(response.context['previous_month'], prev_month)
    133        
     133
    134134    def test_archive_month_date_list(self):
    135135        author = Author(name="John Smith")
    136136        author.save()
    class DayArchiveTests(TestCase):  
    169169        response = self.client.get('/date_based/archive_day/2004/1/21/')
    170170        self.assertEqual(response.status_code, 200)
    171171        self.assertEqual(response.context['object_list'][0], article)
     172
     173    def test_yesterday_and_today(self):
     174        """
     175        Ensure it works for the next day == today (#17192)
     176        """
     177        author = Author.objects.create(name="John Smith")
     178        today = date.today()
     179        yesterday = today - timedelta(days=1)
     180        article1 = Article.objects.create(title="example", author=author,
     181                date_created=yesterday)
     182        article2 = Article.objects.create(title="example", author=author,
     183                date_created=today)
     184        urlbit = yesterday.strftime("%Y/%m/%d").lower()
     185        response = self.client.get('/date_based/archive_day/%s/' % urlbit)
     186        self.assertEqual(response.context['next_day'], today)
Back to Top