Django

Code

Ticket #4919 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

add ?page=last for generic object_list with pagination

Reported by: patrick@vonautomatisch.at Assigned to: nobody
Milestone: Component: Generic views
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

lastpage.diff (3.8 kB) - added by nick@efford.org on 08/21/07 09:51:06.
Refactored patch plus generic views documentation

Change History

08/12/07 05:16:55 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch set to 1.
  • has_patch set to 1.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs set to 1.

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?

08/21/07 09:51:06 changed by nick@efford.org

  • attachment lastpage.diff added.

Refactored patch plus generic views documentation

08/21/07 09:52:38 changed by nick@efford.org

  • needs_better_patch deleted.
  • needs_docs deleted.

08/21/07 17:36:32 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Accepted to Ready for checkin.

09/13/07 20:52:10 changed by russellm

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

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


Add/Change #4919 (add ?page=last for generic object_list with pagination)




Change Properties
Action