Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2093 closed enhancement (duplicate)

[patch] Better paginator

Reported by: SmileyChris Owned by: adrian
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: UI/UX:

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 SmileyChris 8 years ago.
better_paginator_with_paginator_page_addition.patch (6.2 KB) - added by SmileyChris 8 years ago.
PaginatorPage object - page aware ObjectPaginator wrapper
better_paginator_with_paginator_page_addition.2.patch (7.3 KB) - added by SmileyChris 8 years ago.

Download all attachments as: .zip

Change History (9)

Changed 8 years ago by SmileyChris

comment:1 Changed 8 years ago by anonymous

  • Type changed from defect to enhancement

comment:2 Changed 8 years ago by SmileyChris

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.

Changed 8 years ago by SmileyChris

PaginatorPage object - page aware ObjectPaginator wrapper

comment:3 Changed 8 years ago by germish@…

  • Component changed from Admin interface to Core 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 Changed 8 years ago by SmileyChris

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 Changed 8 years ago by mtredinnick

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 Changed 8 years ago by SmileyChris

  • Resolution set to duplicate
  • Status changed from new to closed

Split into two tickets at Malcom's request.

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.