web/views/navigation.py
changeset 8102 619d41a4c770
parent 8101 f9fa2f47572c
child 8110 d743865ba7ed
--- a/web/views/navigation.py	Thu Nov 24 17:00:09 2011 +0100
+++ b/web/views/navigation.py	Tue Nov 29 11:18:46 2011 +0100
@@ -268,8 +268,10 @@
 
 
 def do_paginate(view, rset=None, w=None, show_all_option=True, page_size=None):
-    """write pages index in w stream (default to view.w) and then limit the result
-    set (default to view.rset) to the currently displayed page
+    """write pages index in w stream (default to view.w) and then limit the
+    result set (default to view.rset) to the currently displayed page if we're
+    not explicitly told to display everything (by setting __force_display in
+    req.form)
     """
     req = view._cw
     if rset is None:
@@ -281,26 +283,35 @@
     if nav:
         if w is None:
             w = view.w
-        # get boundaries before component rendering
-        start, stop = nav.page_boundaries()
-        nav.render(w=w)
-        params = dict(req.form)
-        nav.clean_params(params)
-        # make a link to see them all
-        if show_all_option:
+        if req.form.get('__force_display'):
+            # allow to come back to the paginated view
+            params = dict(req.form)
             basepath = req.relative_path(includeparams=False)
-            params['__force_display'] = 1
+            del params['__force_display']
             url = nav.page_url(basepath, params)
             w(u'<div class="displayAllLink"><a href="%s">%s</a></div>\n'
-              % (xml_escape(url), req._('show %s results') % len(rset)))
-        rset.limit(offset=start, limit=stop-start, inplace=True)
+              % (xml_escape(url), req._('show %s results') % nav.page_size))
+        else:
+            # get boundaries before component rendering
+            start, stop = nav.page_boundaries()
+            nav.render(w=w)
+            params = dict(req.form)
+            nav.clean_params(params)
+            # make a link to see them all
+            if show_all_option:
+                basepath = req.relative_path(includeparams=False)
+                params['__force_display'] = 1
+                params['__fromnavigation'] = 1
+                url = nav.page_url(basepath, params)
+                w(u'<div class="displayAllLink"><a href="%s">%s</a></div>\n'
+                  % (xml_escape(url), req._('show %s results') % len(rset)))
+            rset.limit(offset=start, limit=stop-start, inplace=True)
 
 
 def paginate(view, show_all_option=True, w=None, page_size=None, rset=None):
-    """paginate results if the view is paginable and we're not explictly told to
-    display everything (by setting __force_display in req.form)
+    """paginate results if the view is paginable
     """
-    if view.paginable and not view._cw.form.get('__force_display'):
+    if view.paginable:
         do_paginate(view, rset, w, show_all_option, page_size)
 
 # monkey patch base View class to add a .paginate([...])