Opened 17 years ago

Closed 17 years ago

#4919 closed (fixed)

add ?page=last for generic object_list with pagination

Reported by: patrick@… Owned by: nobody
Component: Generic views Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

usecase: you want to link to the last page, but you don´t know how many pages there are. e.g, when you have comments paginated and you want to link to the last comment posted, you could use ?page=last

except (InvalidPage, ValueError):
    if page == 1 and allow_empty:
        object_list = []
+    elif page == 'last':
+        page = paginator._get_pages()
+        object_list = paginator.get_page(page - 1)
    else:
        raise Http404

sorry, but submitting a patch didn´t work the last time, so I just put the code in here.
the above code-snippet is for django.views.generic.list_detail.object_list from line 52.

Attachments (1)

lastpage.diff (3.8 KB ) - added by nick@… 17 years ago.
Refactored patch plus generic views documentation

Download all attachments as: .zip

Change History (5)

comment:1 by Simon G. <dev@…>, 17 years ago

Has patch: set
Needs documentation: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

This sounds like a good idea - but we'll need something in the docs about it. Can someone write up a patch that does Patrick's change, and adds a bit to the generic views docs?

by nick@…, 17 years ago

Attachment: lastpage.diff added

Refactored patch plus generic views documentation

comment:2 by nick@…, 17 years ago

Needs documentation: unset
Patch needs improvement: unset

comment:3 by Simon G. <dev@…>, 17 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(In [6149]) Fixed #4919 -- Added 'last' marker on paginators. Thanks to patrick@… the idea, and nick@… for the patch and docs.

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