Ticket #2386: date_based.py.2.diff
File date_based.py.2.diff, 3.3 KB (added by , 18 years ago) |
---|
-
django/views/generic/date_based.py
133 133 object_list = queryset.filter(**lookup_kwargs) 134 134 if not object_list and not allow_empty: 135 135 raise Http404 136 137 # Get the closest previous post's date, if it exists. 138 lookup_kwargs = {'%s__lte' % date_field: date.replace(day=1) - datetime.timedelta(days=1)} 139 previous_list = queryset.filter(**lookup_kwargs).order_by('-%s' % date_field) 140 if previous_list: 141 previous_month = getattr(previous_list[0], date_field).date() 142 else: 143 previous_month = None 144 145 # Get the closest next post's date, if it exists. 146 if date.month == 12: 147 lookup_kwargs = {'%s__gte' % date_field: date.replace(day=1, month=1, year=date.year + 1)} 148 else: 149 lookup_kwargs = {'%s__gte' % date_field: date.replace(day=1, month=date.month + 1)} 150 next_list = queryset.filter(**lookup_kwargs).order_by(date_field) 151 if next_list: 152 next_month = getattr(next_list[0], date_field).date() 153 else: 154 next_month = None 155 136 156 if not template_name: 137 157 template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower()) 138 158 t = template_loader.get_template(template_name) 139 159 c = RequestContext(request, { 140 160 '%s_list' % template_object_name: object_list, 141 161 'month': date, 142 'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None,143 'previous_month': first_day - datetime.timedelta(days=1),162 'next_month': next_month, 163 'previous_month': previous_month, 144 164 }, context_processors) 145 165 for key, value in extra_context.items(): 146 166 if callable(value): … … 235 255 object_list = queryset.filter(**lookup_kwargs) 236 256 if not allow_empty and not object_list: 237 257 raise Http404 258 259 # Get the closest previous post's date, if it exists. 260 lookup_kwargs = {'%s__lte' % date_field: date - datetime.timedelta(days=1)} 261 previous_list = queryset.filter(**lookup_kwargs).order_by('-%s' % date_field) 262 if previous_list: 263 previous_day = getattr(previous_list[0], date_field).date() 264 else: 265 previous_day = None 266 267 # Get the closest next post's date, if it exists. 268 lookup_kwargs = {'%s__gte' % date_field: date + datetime.timedelta(days=1)} 269 next_list = queryset.filter(**lookup_kwargs).order_by(date_field) 270 if next_list: 271 next_day = getattr(next_list[0], date_field).date() 272 else: 273 next_day = None 274 238 275 if not template_name: 239 276 template_name = "%s/%s_archive_day.html" % (model._meta.app_label, model._meta.object_name.lower()) 240 277 t = template_loader.get_template(template_name) 241 278 c = RequestContext(request, { 242 279 '%s_list' % template_object_name: object_list, 243 280 'day': date, 244 'previous_day': date - datetime.timedelta(days=1),245 'next_day': (date < datetime.date.today()) and (date + datetime.timedelta(days=1)) or None,281 'previous_day': previous_day, 282 'next_day': next_day, 246 283 }, context_processors) 247 284 for key, value in extra_context.items(): 248 285 if callable(value):