app/django/views/generic/date_based.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
   127     first_day = date.replace(day=1)
   127     first_day = date.replace(day=1)
   128     if first_day.month == 12:
   128     if first_day.month == 12:
   129         last_day = first_day.replace(year=first_day.year + 1, month=1)
   129         last_day = first_day.replace(year=first_day.year + 1, month=1)
   130     else:
   130     else:
   131         last_day = first_day.replace(month=first_day.month + 1)
   131         last_day = first_day.replace(month=first_day.month + 1)
   132     lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
   132     lookup_kwargs = {
       
   133         '%s__gte' % date_field: first_day,
       
   134         '%s__lt' % date_field: last_day,
       
   135     }
   133 
   136 
   134     # Only bother to check current date if the month isn't in the past and future objects are requested.
   137     # Only bother to check current date if the month isn't in the past and future objects are requested.
   135     if last_day >= now.date() and not allow_future:
   138     if last_day >= now.date() and not allow_future:
   136         lookup_kwargs['%s__lte' % date_field] = now
   139         lookup_kwargs['%s__lte' % date_field] = now
   137     object_list = queryset.filter(**lookup_kwargs)
   140     object_list = queryset.filter(**lookup_kwargs)
   186     now = datetime.datetime.now()
   189     now = datetime.datetime.now()
   187 
   190 
   188     # Calculate first and last day of week, for use in a date-range lookup.
   191     # Calculate first and last day of week, for use in a date-range lookup.
   189     first_day = date
   192     first_day = date
   190     last_day = date + datetime.timedelta(days=7)
   193     last_day = date + datetime.timedelta(days=7)
   191     lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
   194     lookup_kwargs = {
       
   195         '%s__gte' % date_field: first_day,
       
   196         '%s__lt' % date_field: last_day,
       
   197     }
   192 
   198 
   193     # Only bother to check current date if the week isn't in the past and future objects aren't requested.
   199     # Only bother to check current date if the week isn't in the past and future objects aren't requested.
   194     if last_day >= now.date() and not allow_future:
   200     if last_day >= now.date() and not allow_future:
   195         lookup_kwargs['%s__lte' % date_field] = now
   201         lookup_kwargs['%s__lte' % date_field] = now
   196     object_list = queryset.filter(**lookup_kwargs)
   202     object_list = queryset.filter(**lookup_kwargs)