Django

Code

Ticket #720 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

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

Reported by: m@bagai.com Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

paginator_diff.py (1.3 kB) - added by m@bagai.com on 11/03/05 12:29:27.
svn diff output with added methods

Change History

11/03/05 12:29:27 changed by m@bagai.com

  • attachment paginator_diff.py added.

svn diff output with added methods

05/31/06 23:29:40 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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

06/12/06 08:57:17 changed by vidar@proprius.net

  • status changed from closed to reopened.
  • resolution deleted.

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

06/12/06 17:02:26 changed by SmileyChris

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

01/17/07 23:10:25 changed by SmileyChris

  • status changed from reopened to closed.
  • resolution set to fixed.

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


Add/Change #720 (Added methods to ObjectPaginator for getting the numbers of first and last object on page)




Change Properties
Action