Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7602 closed (fixed)

django.views.generic.date_based.archive_(month|day) includes first day of next (month|day)

Reported by: nullie Owned by: cgrady
Component: Generic views Version: master
Severity: Keywords: aug22sprint
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

archive_month view uses range when searching for entries, but when date_field is of type date (and not datetime), range includes day following specified period

Attachments (1)

7602.patch (10.4 KB) - added by cgrady 6 years ago.
added tests, verified failure->success change

Download all attachments as: .zip

Change History (8)

comment:1 Changed 6 years ago by nullie

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
Index: django/views/generic/date_based.py
===================================================================
--- django/views/generic/date_based.py	(revision 7825)
+++ django/views/generic/date_based.py	(working copy)
@@ -129,7 +129,10 @@
         last_day = first_day.replace(year=first_day.year + 1, month=1)
     else:
         last_day = first_day.replace(month=first_day.month + 1)
-    lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
+    lookup_kwargs = {
+        '%s__gte' % date_field: first_day,
+        '%s__lt' % date_field: last_day
+    }
 
     # Only bother to check current date if the month isn't in the past and future objects are requested.
     if last_day >= now.date() and not allow_future:
@@ -188,7 +191,10 @@
     # Calculate first and last day of week, for use in a date-range lookup.
     first_day = date
     last_day = date + datetime.timedelta(days=7)
-    lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
+    lookup_kwargs = {
+        '%s__gte' % date_field: first_day,
+        '%s__lt' % date_field: last_day
+    }
 
     # Only bother to check current date if the week isn't in the past and future objects aren't requested.
     if last_day >= now.date() and not allow_future:

comment:2 Changed 6 years ago by ericholscher

  • milestone set to 1.0
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 6 years ago by cgrady

  • Owner changed from nobody to cgrady

Changed 6 years ago by cgrady

added tests, verified failure->success change

comment:4 Changed 6 years ago by cgrady

  • Keywords aug22sprint added

comment:5 Changed 6 years ago by cgrady

  • Needs tests unset

comment:6 Changed 6 years ago by brosner

  • Resolution set to fixed
  • Status changed from new to closed

(In [8476]) Fixed #7602 -- Corrected lookup keyword arguments in archive_month and archive_week to properly range when date_field is from DateField. Thanks nullie for the original patch and Colin Grady for the test coverage.

comment:7 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.