Opened 8 years ago

Closed 7 years ago

Last modified 5 years ago

#10458 closed (fixed)

next_month and previous_month in views.generic.date_based.archive_month return wrong dates

Reported by: alasdair Owned by: fperetti
Component: Generic views Version: 1.0
Severity: Keywords: next_month previous_month, pycamp2009
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

next_month and previous_month return different days than the documentation says. This isn't a huge problem, since it is probably the month that is required.

The documentation says that django.views.generic.date_based.archive_month should return:

"next_month: A datetime.date object representing the first day of the next month ..."

However it returns a datetime.date object representing the second day of the next month. This is because on lines 146 and 148, a timedelta is added to last_month, which is already set to the required first date.

Similarly, the documentation says:

"previous_month: A datetime.date object representing the first day of the previous month ..."

when it actually returns the last day of the previous month.

This is my first django bug report, apologies if I've done it in the wrong way.

Attachments (1)

patch.diff (1.6 KB) - added by fperetti 8 years ago.
Add patch and test

Download all attachments as: .zip

Change History (12)

comment:1 Changed 8 years ago by Jacob

milestone: 1.1
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by fperetti

Owner: changed from nobody to fperetti

comment:3 Changed 8 years ago by fperetti

Keywords: pycamp2009 added

Changed 8 years ago by fperetti

Attachment: patch.diff added

Add patch and test

comment:4 Changed 8 years ago by fperetti

without the patch:

fede@Zoka:~/Desktop/django/tests$ ~/django_test/sqlite3 views
======================================================================
FAIL: Regression for #3031: Archives around Feburary include only one month
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/fede/Desktop/django/tests/regressiontests/views/tests/generic/date_based.py", line 77, in test_archive_month_includes_only_month
    self.assertEqual(response.context['next_month'],date(2004, 3, 1))
AssertionError: datetime.date(2004, 3, 2) != datetime.date(2004, 3, 1)

----------------------------------------------------------------------
Ran 31 tests in 1.295s

FAILED (failures=1)

with the patch:

fede@Zoka:~/Desktop/django/tests$ ~/django_test/sqlite3 views
----------------------------------------------------------------------
Ran 31 tests in 1.276s

OK

comment:5 Changed 8 years ago by fperetti

Has patch: set
Resolution: fixed
Status: newclosed

comment:6 Changed 8 years ago by fperetti

Thaks to cramm and nmiyasato!!!

comment:7 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: closedreopened

Since nothing's been checked into the source tree, this isn't fixed. Please read the contributing documentation to learn about ticket statuses.

comment:8 Changed 8 years ago by fperetti

sorry, too much wine..

comment:9 Changed 7 years ago by Ramiro Morales

#10688 reported the same next_month issue and provided a patch with another approach.

comment:10 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: reopenedclosed

(In [10556]) 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.

comment:11 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top