Author: russellm
Date: 2007-09-13 20:52:10 -0500 (Thu, 13 Sep 2007)
New Revision: 6149

Modified:
   django/trunk/django/views/generic/list_detail.py
   django/trunk/docs/generic_views.txt
Log:
Fixed #4919 -- Added 'last' marker on paginators. Thanks to [EMAIL PROTECTED] 
the idea, and [EMAIL PROTECTED] for the patch and docs.


Modified: django/trunk/django/views/generic/list_detail.py
===================================================================
--- django/trunk/django/views/generic/list_detail.py    2007-09-14 01:45:26 UTC 
(rev 6148)
+++ django/trunk/django/views/generic/list_detail.py    2007-09-14 01:52:10 UTC 
(rev 6149)
@@ -49,10 +49,17 @@
         if not page:
             page = request.GET.get('page', 1)
         try:
-            page = int(page)
-            object_list = paginator.get_page(page - 1)
-        except (InvalidPage, ValueError):
-            if page == 1 and allow_empty:
+            page_number = int(page)
+        except ValueError:
+            if page == 'last':
+                page_number = paginator.pages
+            else:
+                # Page is not 'last', nor can it be converted to an int
+                raise Http404
+        try:
+            object_list = paginator.get_page(page_number - 1)
+        except InvalidPage:
+            if page_number == 1 and allow_empty:
                 object_list = []
             else:
                 raise Http404
@@ -60,13 +67,13 @@
             '%s_list' % template_object_name: object_list,
             'is_paginated': paginator.pages > 1,
             'results_per_page': paginate_by,
-            'has_next': paginator.has_next_page(page - 1),
-            'has_previous': paginator.has_previous_page(page - 1),
-            'page': page,
-            'next': page + 1,
-            'previous': page - 1,
-            'last_on_page': paginator.last_on_page(page - 1),
-            'first_on_page': paginator.first_on_page(page - 1),
+            'has_next': paginator.has_next_page(page_number - 1),
+            'has_previous': paginator.has_previous_page(page_number - 1),
+            'page': page_number,
+            'next': page_number + 1,
+            'previous': page_number - 1,
+            'last_on_page': paginator.last_on_page(page_number - 1),
+            'first_on_page': paginator.first_on_page(page_number - 1),
             'pages': paginator.pages,
             'hits' : paginator.hits,
             'page_range' : paginator.page_range

Modified: django/trunk/docs/generic_views.txt
===================================================================
--- django/trunk/docs/generic_views.txt 2007-09-14 01:45:26 UTC (rev 6148)
+++ django/trunk/docs/generic_views.txt 2007-09-14 01:52:10 UTC (rev 6149)
@@ -688,9 +688,8 @@
     * ``paginate_by``: An integer specifying how many objects should be
       displayed per page. If this is given, the view will paginate objects with
       ``paginate_by`` objects per page. The view will expect either a ``page``
-      query string parameter (via ``GET``) containing a 1-based page
-      number, or a ``page`` variable specified in the URLconf. See
-      "Notes on pagination" below.
+      query string parameter (via ``GET``) or a ``page`` variable specified in
+      the URLconf. See "Notes on pagination" below.
 
     * ``template_name``: The full name of a template to use in rendering the
       page. This lets you override the default template name (see below).
@@ -780,7 +779,7 @@
         (r'^objects/page(?P<page>[0-9]+)/$', 'object_list', dict(info_dict))
 
     * Pass the page number via the ``page`` query-string parameter. For
-      example, a URL would look like this:
+      example, a URL would look like this::
 
         /objects/?page=3
 
@@ -789,8 +788,17 @@
       to create a link to every page of results.
 
 These values and lists are is 1-based, not 0-based, so the first page would be
-represented as page ``1``.
+represented as page ``1``. As a special case, you are also permitted to use 
+``last`` as a value for ``page``::
 
+    /objects/?page=last
+
+This allows you to access the final page of results without first having to 
+determine how many pages there are.
+
+Note that ``page`` *must* be either a valid page number or the value ``last``;
+any other value for ``page`` will result in a 404 error.
+
 ``django.views.generic.list_detail.object_detail``
 --------------------------------------------------
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to