[navigation] provide a link back from the full view to the paginated one
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 29 Nov 2011 11:18:46 +0100
changeset 8102 619d41a4c770
parent 8101 f9fa2f47572c
child 8103 5feb10df65cd
[navigation] provide a link back from the full view to the paginated one provide a better marker for navigation induced call detection Closes #2103687
web/component.py
web/views/navigation.py
web/views/tableview.py
--- a/web/component.py	Thu Nov 24 17:00:09 2011 +0100
+++ b/web/component.py	Tue Nov 29 11:18:46 2011 +0100
@@ -100,6 +100,7 @@
 
     def page_url(self, path, params, start=None, stop=None):
         params = dict(params)
+        params['__fromnavigation'] = 1
         if start is not None:
             params[self.start_param] = start
         if stop is not None:
--- 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([...])
--- a/web/views/tableview.py	Thu Nov 24 17:00:09 2011 +0100
+++ b/web/views/tableview.py	Tue Nov 29 11:18:46 2011 +0100
@@ -177,7 +177,7 @@
         or from subsequent calls by the form filter or by the pagination hooks.
         """
         form = self._cw.form
-        return 'fromformfilter' not in form and '__start' not in form
+        return 'fromformfilter' not in form and '__fromnavigation' not in form
 
     def render(self, w, **kwargs):
         assert self.display_filter in (None, 'top', 'bottom'), self.display_filter