rename need_navigation into paginable
paginable has been recently introduced by changeset d4eeaf0393e2.
We already had the need_navigation attribute to control the same
thing (pagination). As paginable sounds like a better name, deprecates
need_navigation (bw compat ok).
Also:
* fix main pagination functions responsability
* deprecate limit_rset_using_nav in favor of paginate/do_paginate
* navigation module should be renamed to pagination at some point
--- a/view.py Thu Jan 14 11:37:08 2010 +0100
+++ b/view.py Fri Jan 15 09:05:40 2010 +0100
@@ -10,6 +10,7 @@
_ = unicode
from cStringIO import StringIO
+from warnings import warn
from simplejson import dumps
@@ -99,12 +100,24 @@
registered = require_group_compat(AppObject.registered)
templatable = True
- need_navigation = True
# content_type = 'application/xhtml+xml' # text/xhtml'
binary = False
add_to_breadcrumbs = True
category = 'view'
+ @property
+ @deprecated('[3.6] need_navigation is deprecated, use .paginable')
+ def need_navigation(self):
+ return True
+
+ @property
+ def paginable(self):
+ if not isinstance(self.__class__.need_navigation, property):
+ warn('[3.6] %s.need_navigation is deprecated, use .paginable'
+ % self.__class__, DeprecationWarninig)
+ return self.need_navigation
+ return True
+
def __init__(self, req=None, rset=None, **kwargs):
super(View, self).__init__(req, rset, **kwargs)
self.w = None
--- a/web/views/basetemplates.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/basetemplates.py Fri Jan 15 09:05:40 2010 +0100
@@ -118,7 +118,7 @@
if etypefilter:
etypefilter.render(w=w)
self.nav_html = UStringIO()
- if view and view.need_navigation:
+ if view:
view.paginate(w=self.nav_html.write)
w(_(self.nav_html.getvalue()))
w(u'<div id="contentmain">\n')
--- a/web/views/calendar.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/calendar.py Fri Jan 15 09:05:40 2010 +0100
@@ -40,7 +40,7 @@
Does apply to ICalendarable compatible entities
"""
__select__ = implements(ICalendarable)
- need_navigation = False
+ paginable = False
content_type = 'text/calendar'
title = _('iCalendar')
templatable = False
@@ -73,7 +73,7 @@
"""
id = 'hcal'
__select__ = implements(ICalendarable)
- need_navigation = False
+ paginable = False
title = _('hCalendar')
#templatable = False
@@ -131,7 +131,7 @@
"""At some point, this view will probably replace ampm calendars"""
id = 'onemonthcal'
__select__ = implements(ICalendarable)
- need_navigation = False
+ paginable = False
title = _('one month')
def call(self):
@@ -322,7 +322,7 @@
"""At some point, this view will probably replace ampm calendars"""
id = 'oneweekcal'
__select__ = implements(ICalendarable)
- need_navigation = False
+ paginable = False
title = _('one week')
def call(self):
--- a/web/views/editforms.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/editforms.py Fri Jan 15 09:05:40 2010 +0100
@@ -76,7 +76,7 @@
title = _('delete')
# don't use navigation, all entities asked to be deleted should be displayed
# else we will only delete the displayed page
- need_navigation = False
+ paginable = False
def call(self, onsubmit=None):
"""ask for confirmation before real deletion"""
--- a/web/views/facets.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/facets.py Fri Jan 15 09:05:40 2010 +0100
@@ -57,7 +57,7 @@
else:
rset = self.rset
vid, divid = None, 'pageContent'
- paginate = view and view.need_navigation
+ paginate = view and view.paginable
return rset, vid, divid, paginate
def call(self, view=None):
--- a/web/views/igeocodable.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/igeocodable.py Fri Jan 15 09:05:40 2010 +0100
@@ -71,7 +71,7 @@
id = 'gmap-view'
__select__ = implements(IGeocodable)
- need_navigation = False
+ paginable = False
def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
self.req.demote_to_html()
--- a/web/views/navigation.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/navigation.py Fri Jan 15 09:05:40 2010 +0100
@@ -148,39 +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.vreg['components'].select_object('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.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.rset
- if getattr(view, 'paginable', True):
- limit_rset_using_paged_nav(view, view.req, rset, w or view.w,
- not view.need_navigation, show_all_option,
- page_size=page_size)
-View.paginate = paginate
-
class NextPrevNavigationComponent(EntityVComponent):
id = 'prevnext'
# register msg not generated since no entity implements IPrevNext in cubicweb
@@ -224,3 +191,55 @@
xml_escape(next.absolute_url()),
self.req._('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_object(
+ '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)
--- a/web/views/old_calendar.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/old_calendar.py Fri Jan 15 09:05:40 2010 +0100
@@ -26,7 +26,7 @@
class _CalendarView(EntityView):
"""base calendar view containing helpful methods to build calendar views"""
__select__ = implements(ICalendarViews,)
- need_navigation = False
+ paginable = False
# Navigation building methods / views ####################################
--- a/web/views/timeline.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/timeline.py Fri Jan 15 09:05:40 2010 +0100
@@ -105,7 +105,7 @@
id = 'timeline'
title = _('timeline')
__select__ = implements(ICalendarable)
- need_navigation = False
+ paginable = False
def call(self, tlunit=None):
self.req.html_headers.define_var('Timeline_urlPrefix', self.req.datadir_url)
rql = self.rset.printable_rql()
--- a/web/views/timetable.py Thu Jan 14 11:37:08 2010 +0100
+++ b/web/views/timetable.py Fri Jan 15 09:05:40 2010 +0100
@@ -28,7 +28,7 @@
id = 'timetable'
title = _('timetable')
__select__ = implements(ITimetableViews)
- need_navigation = False
+ paginable = False
def call(self, title=None):
"""Dumps a timetable from a resultset composed of a note (anything