--- a/web/views/navigation.py Mon Jan 18 19:05:08 2010 +0100
+++ b/web/views/navigation.py Mon Jan 18 19:21:30 2010 +0100
@@ -1,7 +1,7 @@
"""navigation components definition for CubicWeb web client
:organization: Logilab
-:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
+:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
"""
@@ -148,38 +148,6 @@
self.w(u'</div>')
-def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False,
- show_all_option=True, page_size=None):
- if not (forcedisplay or req.form.get('__force_display') is not None):
- nav = self._cw.vreg['components'].select_or_none('navigation', req,
- rset=rset, page_size=page_size)
- if nav:
- # 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:
- url = xml_escape(self._cw.build_url(__force_display=1, **params))
- w(u'<span><a href="%s">%s</a></span>\n'
- % (url, req._('show %s results') % len(rset)))
- rset.limit(offset=start, limit=stop-start, inplace=True)
-
-
-# monkey patch base View class to add a .pagination(req, rset, w, forcedisplay)
-# method to be called on view's result set and printing pages index in the view
-from cubicweb.view import View
-View.pagination = deprecated('.pagination is deprecated, use paginate')(limit_rset_using_paged_nav)
-
-def paginate(view, show_all_option=True, w=None, page_size=None, rset=None):
- if rset is None:
- rset = view.cw_rset
- limit_rset_using_paged_nav(view, view._cw, rset, w or view.w,
- not view.need_navigation, show_all_option,
- page_size=page_size)
-View.paginate = paginate
-
class NextPrevNavigationComponent(EntityVComponent):
__regid__ = 'prevnext'
# register msg not generated since no entity implements IPrevNext in cubicweb
@@ -223,3 +191,55 @@
xml_escape(next.absolute_url()),
self._cw._('i18nprevnext_next'),
xml_escape(cut(next.dc_title(), textsize)))
+
+
+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
+ """
+ req = view.req
+ if rset is None:
+ rset = view.rset
+ nav = req.vreg['components'].select_or_none(
+ 'navigation', req, rset=rset, page_size=page_size)
+ 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:
+ url = xml_escape(view.build_url(__force_display=1, **params))
+ w(u'<span><a href="%s">%s</a></span>\n'
+ % (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)
+ """
+ if not (view.paginable or view.req.form.get('__force_display')):
+ do_paginate(view, rset, w or view.w, show_all_option, page_size)
+
+# monkey patch base View class to add a .paginate([...])
+# method to be called to write pages index in the view and then limit the result
+# set to the current page
+from cubicweb.view import View
+View.do_paginate = do_paginate
+View.paginate = paginate
+
+
+#@deprecated (see below)
+def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False,
+ show_all_option=True, page_size=None):
+ if not (forcedisplay or req.form.get('__force_display') is not None):
+ do_paginate(self, rset, w, show_all_option, page_size)
+
+View.pagination = deprecated('[3.2] .pagination is deprecated, use paginate')(
+ limit_rset_using_paged_nav)
+limit_rset_using_paged_nav = deprecated('[3.6] limit_rset_using_paged_nav is deprecated, use do_paginate')(
+ limit_rset_using_paged_nav)