[web] Move "display all"/ "back to pagination" link generation into the navigation component
authorFlorent Cayré <florent.cayre@logilab.fr>
Wed, 16 Dec 2015 18:08:37 +0100
changeset 11058 23eb30449fe5
parent 11057 0b59724cb3f2
child 11068 a6c4d759be32
[web] Move "display all"/ "back to pagination" link generation into the navigation component This makes the html generation customizable. Closes #9219057
cubicweb/web/component.py
cubicweb/web/views/navigation.py
--- a/cubicweb/web/component.py	Sat Jan 16 13:48:51 2016 +0100
+++ b/cubicweb/web/component.py	Wed Dec 16 18:08:37 2015 +0100
@@ -183,6 +183,28 @@
         url = xml_escape(self.page_url(path, params, start, stop))
         return self.next_page_link_templ % (url, self._cw._(title), content)
 
+    def render_link_back_to_pagination(self, w):
+        """allow to come back to the paginated view"""
+        req = self._cw
+        params = dict(req.form)
+        basepath = req.relative_path(includeparams=False)
+        del params['__force_display']
+        url = self.page_url(basepath, params)
+        w(u'<div class="displayAllLink"><a href="%s">%s</a></div>\n'
+          % (xml_escape(url),
+             req._('back to pagination (%s results)') % self.page_size))
+
+    def render_link_display_all(self, w):
+        """make a link to see them all"""
+        req = self._cw
+        params = dict(req.form)
+        self.clean_params(params)
+        basepath = req.relative_path(includeparams=False)
+        params['__force_display'] = 1
+        params['__fromnavigation'] = 1
+        url = self.page_url(basepath, params)
+        w(u'<div class="displayAllLink"><a href="%s">%s</a></div>\n'
+          % (xml_escape(url), req._('show %s results') % len(self.cw_rset)))
 
 # new contextual components system #############################################
 
--- a/cubicweb/web/views/navigation.py	Sat Jan 16 13:48:51 2016 +0100
+++ b/cubicweb/web/views/navigation.py	Wed Dec 16 18:08:37 2015 +0100
@@ -285,28 +285,13 @@
         if w is None:
             w = view.w
         if req.form.get('__force_display'):
-            # allow to come back to the paginated view
-            params = dict(req.form)
-            basepath = req.relative_path(includeparams=False)
-            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._('back to pagination (%s results)')
-                                  % nav.page_size))
+            nav.render_link_back_to_pagination(w=w)
         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)))
+                nav.render_link_display_all(w=w)
             rset.limit(offset=start, limit=stop-start, inplace=True)