Django

Code

Ticket #7602 (closed: fixed)

Opened 5 months ago

Last modified 3 months ago

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

Reported by: nullie Assigned to: cgrady
Milestone: 1.0 Component: Generic views
Version: SVN Keywords: aug22sprint
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

7602.patch (10.4 kB) - added by cgrady on 08/22/08 18:36:21.
added tests, verified failure->success change

Change History

07/02/08 08:55:55 changed by nullie

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests set to 1.
  • needs_docs changed.
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:

08/08/08 14:30:29 changed by ericholscher

  • stage changed from Unreviewed to Accepted.
  • milestone set to 1.0.

08/22/08 17:37:56 changed by cgrady

  • owner changed from nobody to cgrady.

08/22/08 18:36:21 changed by cgrady

  • attachment 7602.patch added.

added tests, verified failure->success change

08/22/08 18:37:21 changed by cgrady

  • keywords set to aug22sprint.

08/22/08 18:37:41 changed by cgrady

  • needs_tests deleted.

08/22/08 23:46:33 changed by brosner

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #7602 (django.views.generic.date_based.archive_(month|day) includes first day of next (month|day))




Change Properties
Action