Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#2093 closed enhancement (duplicate)

[patch] Better paginator

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

Description

There's no orhpan feature for the paginator. For example:

22 records, num_per_page=10, orphan=2 --> pages==2, len(self.get_page(1))==12

The paginator should work with lists too.

The patch fixes these and also provides more accurate validation.

Attachments (3)

better_paginator.patch (5.0 KB ) - added by Chris Beaven 18 years ago.
better_paginator_with_paginator_page_addition.patch (6.2 KB ) - added by Chris Beaven 18 years ago.
PaginatorPage object - page aware ObjectPaginator wrapper
better_paginator_with_paginator_page_addition.2.patch (7.3 KB ) - added by Chris Beaven 18 years ago.

Download all attachments as: .zip

Change History (9)

by Chris Beaven, 18 years ago

Attachment: better_paginator.patch added

comment:1 by anonymous, 18 years ago

Type: defectenhancement

comment:2 by Chris Beaven, 18 years ago

I have another useful addition to this patch, up to the Django developers whether it should be added. better_paginator.patch is still fine, this new one has those enhancements + a new object in paginator.py:

class PaginatorPage:
    """
    This class is used to work with a page of a paginator object.
    Pass a paginator object, and a valid page number.
    It uses the same methods as a paginator, except you do not need
    to use a page number.
    """

So it's just a page aware paginator object wrapper.

For example, if you have a paginator object in a view, you can set up a PaginatorPage object (passing the paginator and current page number) and then pass this object directly to your template.

by Chris Beaven, 18 years ago

PaginatorPage object - page aware ObjectPaginator wrapper

comment:3 by germish@…, 18 years ago

Component: Admin interfaceCore framework
Keywords: paginator patch added

I like the patch. I haven't tested it, but by looking at the code it does seem to improve upon what's already there. In addition, it addresses my enhancement ticket #2352.

Though, I am not sure the PaginatorPage class would be necessary.

comment:4 by Chris Beaven, 18 years ago

It's definately not necessary and is a seperate enhancement, but I have found it useful.

When you have a batch of objects, it is a lot easier dealing with a PaginatorPage object than a Paginator object in the template. I mean why should the template have to know which page it's on when getting the correct batch? It shouldn't - therefore this helps keep that logic in the view while still providing all the useful Paginator methods to the template author.

comment:5 by Malcolm Tredinnick, 18 years ago

Could you split this up into two patches please and move the new functionality (the PaginatorPage class) to a new ticket. I am not too enthused (at least, not yet) about the PaginatorPage without it undergoing a bit more work, but the orphan/widow stuff looks pretty straightforward. It's just hard to address two completely separate features in one ticket (the fact that they both talk about pagination is just a coincidence). So if you could split it up and move part of it to a new ticket, then we can handle each part separately.

comment:6 by Chris Beaven, 18 years ago

Resolution: duplicate
Status: newclosed

Split into two tickets at Malcom's request.

#2575 - orphans and general additions to paginator
#2576 - new PaginatorPage object

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