Changeset 3457
- Timestamp:
- 07/27/06 11:36:02 (2 years ago)
- Files:
-
- django/trunk/django/views/generic/date_based.py (modified) (14 diffs)
- django/trunk/docs/generic_views.txt (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/views/generic/date_based.py
r3070 r3457 8 8 template_name=None, template_loader=loader, 9 9 extra_context=None, allow_empty=False, context_processors=None, 10 mimetype=None ):10 mimetype=None, allow_future=False): 11 11 """ 12 12 Generic top-level archive of date-based objects. … … 21 21 if extra_context is None: extra_context = {} 22 22 model = queryset.model 23 queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()}) 23 if not allow_future: 24 queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()}) 24 25 date_list = queryset.dates(date_field, 'year')[::-1] 25 26 if not date_list and not allow_empty: … … 48 49 template_loader=loader, extra_context=None, allow_empty=False, 49 50 context_processors=None, template_object_name='object', mimetype=None, 50 make_object_list=False ):51 make_object_list=False, allow_future=False): 51 52 """ 52 53 Generic yearly archive view. … … 68 69 lookup_kwargs = {'%s__year' % date_field: year} 69 70 70 # Only bother to check current date if the year isn't in the past .71 if int(year) >= now.year :71 # Only bother to check current date if the year isn't in the past and future objects aren't requested. 72 if int(year) >= now.year and not allow_future: 72 73 lookup_kwargs['%s__lte' % date_field] = now 73 74 date_list = queryset.filter(**lookup_kwargs).dates(date_field, 'month') … … 96 97 month_format='%b', template_name=None, template_loader=loader, 97 98 extra_context=None, allow_empty=False, context_processors=None, 98 template_object_name='object', mimetype=None ):99 template_object_name='object', mimetype=None, allow_future=False): 99 100 """ 100 101 Generic monthly archive view. … … 128 129 lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)} 129 130 130 # Only bother to check current date if the month isn't in the past .131 if last_day >= now.date() :131 # Only bother to check current date if the month isn't in the past and future objects are requested. 132 if last_day >= now.date() and not allow_future: 132 133 lookup_kwargs['%s__lte' % date_field] = now 133 134 object_list = queryset.filter(**lookup_kwargs) 134 135 if not object_list and not allow_empty: 135 136 raise Http404 137 138 # Calculate the next month, if applicable. 139 if allow_future: 140 next_month = last_day + datetime.timedelta(days=1) 141 elif last_day < datetime.date.today(): 142 next_month = last_day + datetime.timedelta(days=1) 143 else: 144 next_month = None 145 136 146 if not template_name: 137 147 template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower()) … … 140 150 '%s_list' % template_object_name: object_list, 141 151 'month': date, 142 'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None,152 'next_month': next_month, 143 153 'previous_month': first_day - datetime.timedelta(days=1), 144 154 }, context_processors) … … 153 163 template_name=None, template_loader=loader, 154 164 extra_context=None, allow_empty=True, context_processors=None, 155 template_object_name='object', mimetype=None ):165 template_object_name='object', mimetype=None, allow_future=False): 156 166 """ 157 167 Generic weekly archive view. … … 178 188 lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)} 179 189 180 # Only bother to check current date if the week isn't in the past .181 if last_day >= now.date() :190 # Only bother to check current date if the week isn't in the past and future objects aren't requested. 191 if last_day >= now.date() and not allow_future: 182 192 lookup_kwargs['%s__lte' % date_field] = now 183 193 object_list = queryset.filter(**lookup_kwargs) … … 202 212 template_loader=loader, extra_context=None, allow_empty=False, 203 213 context_processors=None, template_object_name='object', 204 mimetype=None ):214 mimetype=None, allow_future=False): 205 215 """ 206 216 Generic daily archive view. … … 230 240 } 231 241 232 # Only bother to check current date if the date isn't in the past .233 if date >= now.date() :242 # Only bother to check current date if the date isn't in the past and future objects aren't requested. 243 if date >= now.date() and not allow_future: 234 244 lookup_kwargs['%s__lte' % date_field] = now 235 245 object_list = queryset.filter(**lookup_kwargs) 236 246 if not allow_empty and not object_list: 237 247 raise Http404 248 249 # Calculate the next day, if applicable. 250 if allow_future: 251 next_day = date + datetime.timedelta(days=1) 252 elif date < datetime.date.today(): 253 next_day = date + datetime.timedelta(days=1) 254 else: 255 next_day = None 256 238 257 if not template_name: 239 258 template_name = "%s/%s_archive_day.html" % (model._meta.app_label, model._meta.object_name.lower()) … … 243 262 'day': date, 244 263 'previous_day': date - datetime.timedelta(days=1), 245 'next_day': (date < datetime.date.today()) and (date + datetime.timedelta(days=1)) or None,264 'next_day': next_day, 246 265 }, context_processors) 247 266 for key, value in extra_context.items(): … … 268 287 slug_field=None, template_name=None, template_name_field=None, 269 288 template_loader=loader, extra_context=None, context_processors=None, 270 template_object_name='object', mimetype=None ):289 template_object_name='object', mimetype=None, allow_future=False): 271 290 """ 272 291 Generic detail view from year/month/day/slug or year/month/day/id structure. … … 290 309 } 291 310 292 # Only bother to check current date if the date isn't in the past .293 if date >= now.date() :311 # Only bother to check current date if the date isn't in the past and future objects aren't requested. 312 if date >= now.date() and not allow_future: 294 313 lookup_kwargs['%s__lte' % date_field] = now 295 314 if object_id: django/trunk/docs/generic_views.txt
r3071 r3457 149 149 150 150 A top-level index page showing the "latest" objects, by date. Objects with 151 a date in the *future* are not included. 151 a date in the *future* are not included unless you set ``allow_future`` to 152 ``True``. 152 153 153 154 **Required arguments:** … … 185 186 * ``mimetype``: The MIME type to use for the resulting document. Defaults 186 187 to the value of the ``DEFAULT_MIME_TYPE`` setting. 188 189 * ``allow_future``: A boolean specifying whether to include "future" 190 objects on this page, where "future" means objects in which the field 191 specified in ``date_field`` is greater than the current date/time. By 192 default, this is ``False``. 187 193 188 194 **Template name:** … … 218 224 219 225 A yearly archive page showing all available months in a given year. Objects 220 with a date in the *future* are not displayed. 226 with a date in the *future* are not displayed unless you set ``allow_future`` 227 to ``True``. 221 228 222 229 **Required arguments:** … … 266 273 to the value of the ``DEFAULT_MIME_TYPE`` setting. 267 274 275 * ``allow_future``: A boolean specifying whether to include "future" 276 objects on this page, where "future" means objects in which the field 277 specified in ``date_field`` is greater than the current date/time. By 278 default, this is ``False``. 279 268 280 **Template name:** 269 281 … … 297 309 298 310 A monthly archive page showing all objects in a given month. Objects with a 299 date in the *future* are not displayed. 311 date in the *future* are not displayed unless you set ``allow_future`` to 312 ``True``. 300 313 301 314 **Required arguments:** … … 347 360 to the value of the ``DEFAULT_MIME_TYPE`` setting. 348 361 362 * ``allow_future``: A boolean specifying whether to include "future" 363 objects on this page, where "future" means objects in which the field 364 specified in ``date_field`` is greater than the current date/time. By 365 default, this is ``False``. 366 349 367 **Template name:** 350 368 … … 379 397 380 398 A weekly archive page showing all objects in a given week. Objects with a date 381 in the *future* are not displayed .399 in the *future* are not displayed unless you set ``allow_future`` to ``True``. 382 400 383 401 **Required arguments:** … … 423 441 to the value of the ``DEFAULT_MIME_TYPE`` setting. 424 442 443 * ``allow_future``: A boolean specifying whether to include "future" 444 objects on this page, where "future" means objects in which the field 445 specified in ``date_field`` is greater than the current date/time. By 446 default, this is ``False``. 447 425 448 **Template name:** 426 449 … … 446 469 447 470 A day archive page showing all objects in a given day. Days in the future throw 448 a 404 error, regardless of whether any objects exist for future days. 471 a 404 error, regardless of whether any objects exist for future days, unless 472 you set ``allow_future`` to ``True``. 449 473 450 474 **Required arguments:** … … 502 526 to the value of the ``DEFAULT_MIME_TYPE`` setting. 503 527 528 * ``allow_future``: A boolean specifying whether to include "future" 529 objects on this page, where "future" means objects in which the field 530 specified in ``date_field`` is greater than the current date/time. By 531 default, this is ``False``. 532 504 533 **Template name:** 505 534 … … 538 567 **Description:** 539 568 540 A page representing an individual object. 569 A page representing an individual object. If the object has a date value in the 570 future, the view will throw a 404 error by default, unless you set 571 ``allow_future`` to ``True``. 541 572 542 573 **Required arguments:** … … 605 636 to the value of the ``DEFAULT_MIME_TYPE`` setting. 606 637 638 * ``allow_future``: A boolean specifying whether to include "future" 639 objects on this page, where "future" means objects in which the field 640 specified in ``date_field`` is greater than the current date/time. By 641 default, this is ``False``. 642 607 643 **Template name:** 608 644
