Opened 19 years ago

Closed 18 years ago

#720 closed enhancement (fixed)

Added methods to ObjectPaginator for getting the numbers of first and last object on page

Reported by: m@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi,

I added two convenience methods to django/core/paginator.py for getting the numbers of the first and last object on the current page, relative to the total number of objects found (paginator.hits):

  • first_on_page(page_number)
  • last_on_page(page_number)

The purpose of having these methods would be to make it easy for the view author to make these values available to the template author who would commonly need to output stuff like:

Now showing x through y of z matching records

I have tried to implement these methods in the style of the other "public" methods of the ObjectPaginator class, so that they take the page number as their only argument when called externally. I am still fairly new to Python and to submitting patches to Django, so please feel free to rename/correct at will.

If these methods are incorporated into the default distribution, I think the generic views should be modified accordingly to provide these values. I would be happy to make those changes, if needed.

Thanks!

/Morten

Attachments (1)

paginator_diff.py (1.3 KB ) - added by m@… 19 years ago.
svn diff output with added methods

Download all attachments as: .zip

Change History (5)

by m@…, 19 years ago

Attachment: paginator_diff.py added

svn diff output with added methods

comment:1 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [3040]) Fixed #720 -- Added first_on_page() and last_on_page() methods to ObjectPaginator. Thanks, m@…

comment:2 by vidar@…, 18 years ago

Resolution: fixed
Status: closedreopened

A small correction is needed here.
If you call last_on_page before a call to _get_pages you get a TypeError since self._pages has not been set.

unsupported operand type(s) for -: 'NoneType' and 'int'

This is a small thing since usually you will have called this method but it should be easily corrected I suppose.

br
Vidar

comment:3 by Chris Beaven, 18 years ago

The fix for this (and adding some functionality) is waiting in #2093.

comment:4 by Chris Beaven, 18 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in [4041] (as part of #2575)

Note: See TracTickets for help on using tickets.
Back to Top