Opened 15 years ago

Closed 15 years ago

Last modified 12 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: no UI/UX: no

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 15 years ago.
Add patch and test

Download all attachments as: .zip

Change History (12)

comment:1 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 by fperetti, 15 years ago

Owner: changed from nobody to fperetti

comment:3 by fperetti, 15 years ago

Keywords: pycamp2009 added

by fperetti, 15 years ago

Attachment: patch.diff added

Add patch and test

comment:4 by fperetti, 15 years ago

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 by fperetti, 15 years ago

Has patch: set
Resolution: fixed
Status: newclosed

comment:6 by fperetti, 15 years ago

Thaks to cramm and nmiyasato!!!

comment:7 by Malcolm Tredinnick, 15 years ago

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 by fperetti, 15 years ago

sorry, too much wine..

comment:9 by Ramiro Morales, 15 years ago

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

comment:10 by Russell Keith-Magee, 15 years ago

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 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

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