Ticket #14711: 14711.diff
File 14711.diff, 4.2 KB (added by , 14 years ago) |
---|
-
django/views/generic/dates.py
70 70 Get the previous valid month. 71 71 """ 72 72 first_day, last_day = _month_bounds(date) 73 prev = (first_day - datetime.timedelta(days=1)) .replace(day=1)73 prev = (first_day - datetime.timedelta(days=1)) 74 74 return _get_next_prev_month(self, prev, is_previous=True, use_first_day=True) 75 75 76 76 … … 519 519 This is a bit complicated since it handles both next and previous months 520 520 and days (for MonthArchiveView and DayArchiveView); hence the coupling to generic_view. 521 521 522 However in ess ance the logic comes down to:522 However in essence the logic comes down to: 523 523 524 524 * If allow_empty and allow_future are both true, this is easy: just 525 525 return the naive result (just the next/previous day or month, … … 549 549 # whose date_field is at least (greater than/less than) the given 550 550 # naive result 551 551 else: 552 # Construct a lookup and an ordering depending on w eather we're doing552 # Construct a lookup and an ordering depending on whether we're doing 553 553 # a previous date or a next date lookup. 554 554 if is_previous: 555 555 lookup = {'%s__lte' % date_field: naive_result} … … 572 572 result = result.date() 573 573 574 574 # For month views, we always want to have a date that's the first of the 575 # month for consist ancy's sake.575 # month for consistency's sake. 576 576 if result and use_first_day: 577 577 result = result.replace(day=1) 578 578 -
tests/regressiontests/generic_views/dates.py
359 359 360 360 def test_invalid_url(self): 361 361 self.assertRaises(AttributeError, self.client.get, "/dates/books/2008/oct/01/nopk/") 362 363 class NextPreviousMonthViewTests(TestCase): 364 urls = 'regressiontests.generic_views.urls' 365 366 def setUp(self): 367 self.pubdate_list = [ 368 datetime.date(2010, month, day) 369 for month,day in ((9,1), (10,2), (11,3)) 370 ] 371 for pubdate in self.pubdate_list: 372 name = str(pubdate) 373 Book.objects.create(name=name, slug=name, pages=100, pubdate=pubdate) 374 375 def test_previous_month_bug(self): 376 res = self.client.get('/dates/books/2010/nov/allow_empty/') 377 self.assertEqual(res.status_code, 200) 378 self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1)) 379 # The following test demonstrates the bug 380 res = self.client.get('/dates/books/2010/nov/') 381 self.assertEqual(res.status_code, 200) 382 self.assertEqual(res.context['previous_month'], datetime.date(2010,10,1)) 383 # The bug does not occur here because a Book with pubdate of Sep 1 exists 384 res = self.client.get('/dates/books/2010/oct/') 385 self.assertEqual(res.status_code, 200) 386 self.assertEqual(res.context['previous_month'], datetime.date(2010,9,1)) -
tests/regressiontests/generic_views/tests.py
1 1 from regressiontests.generic_views.base import ViewTest, TemplateViewTest, RedirectViewTest 2 from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests 2 from regressiontests.generic_views.dates import ArchiveIndexViewTests, YearArchiveViewTests, MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests, DateDetailViewTests, NextPreviousMonthViewTests 3 3 from regressiontests.generic_views.detail import DetailViewTest 4 4 from regressiontests.generic_views.edit import ModelFormMixinTests, CreateViewTests, UpdateViewTests, DeleteViewTests 5 5 from regressiontests.generic_views.list import ListViewTests