Django

Code

Ticket #3391 (closed: duplicate)

Opened 2 years ago

Last modified 2 years ago

[patch] django.views.generic.list_detail.object_list - add context variables on pagination

Reported by: Max Derkachev <mderk@yandex.ru> Assigned to: jacob
Milestone: Component: Generic views
Version: SVN Keywords:
Cc: frankie@grimboy.co.uk Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The patch is for django.views.generic.list_detail.object_list and the docs. It adds the following variables to context, when the paginated object_list is required: 1. pages_list - the list of page numbers; 2. page_start - the number of the first item on the page; 3. page_end - the number of the last item on the page.

They are obviously missing, and are very useful when one need to construct pagination control like this:

PREV 1 2 3 4 5 6 7 NEXT
showing 10-20 of 100 items

the template source will be like this:

<a href="#">PREV</a>
{% for page_num in pages_list %}
{{ page_num }}
{% endfor %}
<a href="#">NEXT</a>
showing {{ page_start }}-{{ page_end }} of {{ hits }}

Attachments

generic_object_list.patch (1.6 kB) - added by Max Derkachev <mderk@yandex.ru> on 01/29/07 11:10:09.
The patch
generic_object_list.2.patch (2.4 kB) - added by Max Derkachev <mderk@yandex.ru> on 01/30/07 12:27:28.
the better patch

Change History

01/29/07 11:10:09 changed by Max Derkachev <mderk@yandex.ru>

  • attachment generic_object_list.patch added.

The patch

01/30/07 11:42:48 changed by Gary Wilson <gary.wilson@gmail.com>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • needs_tests changed.
  • needs_docs changed.

I would say that all this stuff related to pagination needs to be contained in the ObjectPaginator? class. This way it can get re-used in any other view and not just the object_list generic view. For example, allow ObjectPaginator? constructor to be passed the page number, which would set, say, item_start, item_end, and pages attributes.

01/30/07 12:26:50 changed by Max Derkachev <mderk@yandex.ru>

Indeed, I missed the fact that ObjectPaginator? has first_on_page and last_on_page methods. So, I updated the patch and added one property to ObjectPaginator? to get the list of page numbers. I've also changed the names of variables to more meaningful.

The subtle problem is that ObjectPaginator? uses 0-based page number (the view uses 1-based), and one that uses it should always remember that when calling ObjectPaginator? members. E.g. the constructor is called with page - 1 from the view. So, to get first_item, the view should call them as paginator.first_on_page(page - 1). But I guess that should not chnange since it may break BC, if somebody uses ObjectPaginator? in custom views.

01/30/07 12:27:28 changed by Max Derkachev <mderk@yandex.ru>

  • attachment generic_object_list.2.patch added.

the better patch

02/02/07 10:18:01 changed by frankie@grimboy.co.uk

  • cc set to frankie@grimboy.co.uk.
  • status changed from new to closed.
  • resolution set to duplicate.

Dupe of #3169 and #3170.


Add/Change #3391 ([patch] django.views.generic.list_detail.object_list - add context variables on pagination)




Change Properties
Action