4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
|
9 _ = unicode |
9 |
10 |
10 from rql.nodes import VariableRef, Constant |
11 from rql.nodes import VariableRef, Constant |
11 |
12 |
12 from logilab.mtconverter import html_escape |
13 from logilab.mtconverter import html_escape |
13 from logilab.common.deprecation import obsolete |
14 from logilab.common.deprecation import obsolete |
16 from cubicweb.selectors import (paginated_rset, sorted_rset, |
17 from cubicweb.selectors import (paginated_rset, sorted_rset, |
17 primary_view, match_context_prop, |
18 primary_view, match_context_prop, |
18 one_line_rset, implements) |
19 one_line_rset, implements) |
19 from cubicweb.common.uilib import cut |
20 from cubicweb.common.uilib import cut |
20 from cubicweb.web.component import EntityVComponent, NavigationComponent |
21 from cubicweb.web.component import EntityVComponent, NavigationComponent |
21 |
|
22 _ = unicode |
|
23 |
22 |
24 |
23 |
25 class PageNavigation(NavigationComponent): |
24 class PageNavigation(NavigationComponent): |
26 |
25 |
27 def call(self): |
26 def call(self): |
46 w(u' %s' % self.next_link(params)) |
45 w(u' %s' % self.next_link(params)) |
47 w(u'</div>') |
46 w(u'</div>') |
48 |
47 |
49 def index_display(self, start, stop): |
48 def index_display(self, start, stop): |
50 return u'%s - %s' % (start+1, stop+1) |
49 return u'%s - %s' % (start+1, stop+1) |
|
50 |
51 |
51 |
52 class SortedNavigation(NavigationComponent): |
52 class SortedNavigation(NavigationComponent): |
53 """sorted navigation apply if navigation is needed (according to page size) |
53 """sorted navigation apply if navigation is needed (according to page size) |
54 and if the result set is sorted |
54 and if the result set is sorted |
55 """ |
55 """ |
146 self.w(u'</div>') |
146 self.w(u'</div>') |
147 |
147 |
148 |
148 |
149 def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False, |
149 def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False, |
150 show_all_option=True, page_size=None): |
150 show_all_option=True, page_size=None): |
151 showall = forcedisplay or req.form.get('__force_display') is not None |
151 if not (forcedisplay or req.form.get('__force_display') is not None): |
152 nav = not showall and self.vreg.select_component('navigation', req, rset, |
152 nav = self.vreg.select_object('components', 'navigation', req, |
153 page_size=page_size) |
153 rset=rset, page_size=page_size) |
154 if nav: |
154 if nav: |
155 # get boundaries before component rendering |
155 # get boundaries before component rendering |
156 start, stop = nav.page_boundaries() |
156 start, stop = nav.page_boundaries() |
157 nav.render(w=w) |
157 nav.render(w=w) |
158 params = dict(req.form) |
158 params = dict(req.form) |
159 nav.clean_params(params) |
159 nav.clean_params(params) |
160 # make a link to see them all |
160 # make a link to see them all |
161 if show_all_option: |
161 if show_all_option: |
162 url = html_escape(self.build_url(__force_display=1, **params)) |
162 url = html_escape(self.build_url(__force_display=1, **params)) |
163 w(u'<p><a href="%s">%s</a></p>\n' |
163 w(u'<p><a href="%s">%s</a></p>\n' |
164 % (url, req._('show %s results') % len(rset))) |
164 % (url, req._('show %s results') % len(rset))) |
165 rset.limit(offset=start, limit=stop-start, inplace=True) |
165 rset.limit(offset=start, limit=stop-start, inplace=True) |
166 |
166 |
167 |
167 |
168 # monkey patch base View class to add a .pagination(req, rset, w, forcedisplay) |
168 # monkey patch base View class to add a .pagination(req, rset, w, forcedisplay) |
169 # method to be called on view's result set and printing pages index in the view |
169 # method to be called on view's result set and printing pages index in the view |
170 from cubicweb.view import View |
170 from cubicweb.view import View |