Ticket #3585: gv_datebased_object_date.diff
File gv_datebased_object_date.diff, 8.8 KB (added by , 18 years ago) |
---|
-
django/views/generic/date_based.py
106 106 month: 107 107 (date) this month 108 108 next_month: 109 (date) the first day of the next month, or None if the next month is in the future 109 (date) the first day of the next month, or None if the next month is in the future and allow_future is False 110 110 previous_month: 111 111 (date) the first day of the previous month 112 112 object_list: 113 113 list of objects published in the given month 114 next_object_date: 115 (date) the date for the first object after the beginning of the next month, or None if there is no such object or if the date is in the future and allow_future is False 116 previous_object_date: 117 (date) the date for the last object before the beginning of the this month, or None if there is no such object 114 118 """ 115 119 if extra_context is None: extra_context = {} 116 120 try: … … 144 148 else: 145 149 next_month = None 146 150 151 # Get the closest past object's date, if it exists. 152 lookup_kwargs = {'%s__lt' % date_field: first_day} 153 previous_list = queryset.filter(**lookup_kwargs).order_by('-%s' % date_field) 154 if previous_list: 155 previous_object_date = getattr(previous_list[0], date_field).date() 156 else: 157 previous_object_date = None 158 159 # Get the closest future object's date, if it exists and is allowed 160 if last_day >= now.date() and not allow_future: 161 next_object_date = None 162 else: 163 lookup_kwargs = {'%s__gte' % date_field: last_day} 164 next_list = queryset.filter(**lookup_kwargs).order_by(date_field) 165 if next_list: 166 next_object_date = getattr(next_list[0], date_field).date() 167 else: 168 next_object_date = None 169 147 170 if not template_name: 148 171 template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower()) 149 172 t = template_loader.get_template(template_name) … … 152 175 'month': date, 153 176 'next_month': next_month, 154 177 'previous_month': first_day - datetime.timedelta(days=1), 178 'next_%s_date' % template_object_name: next_object_date, 179 'previous_%s_date' % template_object_name: previous_object_date, 155 180 }, context_processors) 156 181 for key, value in extra_context.items(): 157 182 if callable(value): … … 225 250 previous_day 226 251 (datetime) the previous day 227 252 next_day 228 (datetime) the next day, or None if the current day is today 253 (datetime) the next day, or None if the current day is today and allow_future is False 254 next_object_date: 255 (date) the date for the first object after the beginning of the next month, or None if there is no such object or if the date is in the future and allow_future is False 256 previous_object_date: 257 (date) the date for the last object before the beginning of the this month, or None if there is no such object 229 258 """ 230 259 if extra_context is None: extra_context = {} 231 260 try: … … 256 285 else: 257 286 next_day = None 258 287 288 # Get the closest past object's date, if it exists. 289 if isinstance(model._meta.get_field(date_field), DateTimeField): 290 lookup_kwargs = {'%s__lt' % date_field: datetime.datetime.combine(date, datetime.time.min)} 291 else: 292 lookup_kwargs = {'%s__lt' % date_field: date} 293 previous_list = queryset.filter(**lookup_kwargs).order_by('-%s' % date_field) 294 if previous_list: 295 previous_object_date = getattr(previous_list[0], date_field).date() 296 else: 297 previous_object_date = None 298 299 # Get the closest future object's date, if it exists and is allowed 300 if date >= now.date() and not allow_future: 301 next_object_date = None 302 else: 303 if isinstance(model._meta.get_field(date_field), DateTimeField): 304 lookup_kwargs = {'%s__gt' % date_field: datetime.datetime.combine(date, datetime.time.min)} 305 else: 306 lookup_kwargs = {'%s__gt' % date_field: date} 307 next_list = queryset.filter(**lookup_kwargs).order_by(date_field) 308 if next_list: 309 next_object_date = getattr(next_list[0], date_field).date() 310 else: 311 next_object_date = None 312 313 259 314 if not template_name: 260 315 template_name = "%s/%s_archive_day.html" % (model._meta.app_label, model._meta.object_name.lower()) 261 316 t = template_loader.get_template(template_name) … … 264 319 'day': date, 265 320 'previous_day': date - datetime.timedelta(days=1), 266 321 'next_day': next_day, 322 'next_%s_date' % template_object_name: next_object_date, 323 'previous_%s_date' % template_object_name: previous_object_date, 267 324 }, context_processors) 268 325 for key, value in extra_context.items(): 269 326 if callable(value): -
docs/generic_views.txt
384 384 * ``month``: A ``datetime.date`` object representing the given month. 385 385 386 386 * ``next_month``: A ``datetime.date`` object representing the first day of 387 the next month. If the next month is in the future , this will be388 `` None``.387 the next month. If the next month is in the future and ``allow_future`` is 388 ``False``, this will be ``None``. 389 389 390 390 * ``previous_month``: A ``datetime.date`` object representing the first day 391 391 of the previous month. Unlike ``next_month``, this will never be 392 392 ``None``. 393 393 394 * ``previous_month``: A ``datetime.date`` object representing the day of the 395 last post of the previous month. If there is no such post this will be 396 ``None``. 397 394 398 * ``object_list``: A list of objects available for the given month. This 395 399 variable's name depends on the ``template_object_name`` parameter, which 396 400 is ``'object'`` by default. If ``template_object_name`` is ``'foo'``, 397 401 this variable's name will be ``foo_list``. 398 402 403 * ``next_object_date``: A ``datetime.date`` object representing the date of the 404 first object dated after the start of next month. If there is no such object 405 or if the date is in the future and ``allow_future`` is ``False``, this will 406 be ``None``. This variable's name depends on the ``template_object_name`` 407 parameter, which is ``'object'`` by default. If ``template_object_name`` is 408 ``'foo'``, this variable's name will be ``next_foo_date``. 409 410 * ``previous_object_date``: A ``datetime.date`` object representing the date of 411 the last object dated before the start of the given month. If there is no such 412 object, this will be ``None``. This variable's name depends on the 413 ``template_object_name`` parameter, which is ``'object'`` by default. 414 If ``template_object_name`` is ``'foo'``, this variable's name will be 415 ``previous_foo_date``. 416 399 417 .. _strftime docs: http://www.python.org/doc/current/lib/module-time.html#l2h-1941 400 418 401 419 ``django.views.generic.date_based.archive_week`` … … 550 568 * ``day``: A ``datetime.date`` object representing the given day. 551 569 552 570 * ``next_day``: A ``datetime.date`` object representing the next day. If 553 the next day is in the future, this will be ``None``. 571 the next day is in the future, and ``allow_future`` is ``False``, this 572 will be ``None``. 554 573 555 574 * ``previous_day``: A ``datetime.date`` object representing the given day. 556 575 Unlike ``next_day``, this will never be ``None``. … … 560 579 is ``'object'`` by default. If ``template_object_name`` is ``'foo'``, 561 580 this variable's name will be ``foo_list``. 562 581 582 * ``next_object_date``: A ``datetime.date`` object representing the date of the 583 first object dated after the given day. If there is no such object or if the 584 date is in the future and ``allow_future`` is ``False``, this will be ``None``. 585 This variable's name depends on the ``template_object_name`` parameter, which 586 is ``'object'`` by default. If ``template_object_name`` is ``'foo'``, 587 this variable's name will be ``next_foo_date``. 588 589 * ``previous_object_date``: A ``datetime.date`` object representing the date of 590 the last object dated before the given day. If there is no such object, this 591 will be ``None``. This variable's name depends on the ``template_object_name`` 592 parameter, which is ``'object'`` by default. If ``template_object_name`` is 593 ``'foo'``, this variable's name will be ``previous_foo_date``. 594 595 563 596 ``django.views.generic.date_based.archive_today`` 564 597 ------------------------------------------------- 565 598