author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 30 Sep 2010 14:58:57 +0200 | |
changeset 6368 | f907cc7f2875 |
parent 6141 | b8287e54b528 |
child 6864 | ea95004494a2 |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5615
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
18 |
"""navigation components definition for CubicWeb web client""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
2259 | 21 |
_ = unicode |
0 | 22 |
|
23 |
from rql.nodes import VariableRef, Constant |
|
24 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2259
diff
changeset
|
25 |
from logilab.mtconverter import xml_escape |
2613
5e19c2bb370e
R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2381
diff
changeset
|
26 |
from logilab.common.deprecation import deprecated |
0 | 27 |
|
692
800592b8d39b
replace deprecated cubicweb.common.selectors by its new module path (cubicweb.selectors)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
588
diff
changeset
|
28 |
from cubicweb.selectors import (paginated_rset, sorted_rset, |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
29 |
adaptable, implements) |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3777
diff
changeset
|
30 |
from cubicweb.uilib import cut |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
31 |
from cubicweb.view import EntityAdapter, implements_adapter_compat |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
32 |
from cubicweb.web.component import EmptyComponent, EntityCtxComponent, NavigationComponent |
0 | 33 |
|
34 |
||
35 |
class PageNavigation(NavigationComponent): |
|
36 |
||
37 |
def call(self): |
|
38 |
"""displays a resultset by page""" |
|
5615
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
39 |
params = dict(self._cw.form) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
40 |
self.clean_params(params) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
41 |
basepath = self._cw.relative_path(includeparams=False) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
42 |
self.w(u'<div class="pagination">') |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
43 |
self.w(u'%s ' % self.previous_link(basepath, params)) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
44 |
self.w(u'[ %s ]' % |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
45 |
u' | '.join(self.iter_page_links(basepath, params))) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
46 |
self.w(u' %s' % self.next_link(basepath, params)) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
47 |
self.w(u'</div>') |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
48 |
|
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
49 |
def index_display(self, start, stop): |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
50 |
return u'%s - %s' % (start+1, stop+1) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
51 |
|
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
52 |
def iter_page_links(self, basepath, params): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
53 |
rset = self.cw_rset |
0 | 54 |
page_size = self.page_size |
55 |
start = 0 |
|
56 |
while start < rset.rowcount: |
|
57 |
stop = min(start + page_size - 1, rset.rowcount - 1) |
|
5615
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
58 |
yield self.page_link(basepath, params, start, stop, |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
59 |
self.index_display(start, stop)) |
0 | 60 |
start = stop + 1 |
5615
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
61 |
|
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
62 |
|
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
63 |
class PageNavigationSelect(PageNavigation): |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
64 |
"""displays a resultset by page as PageNavigationSelect but in a <select>, |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
65 |
better when there are a lot of results. |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
66 |
""" |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
67 |
__select__ = paginated_rset(4) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
68 |
|
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
69 |
page_link_templ = u'<option value="%s" title="%s">%s</option>' |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
70 |
selected_page_link_templ = u'<option value="%s" selected="selected" title="%s">%s</option>' |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
71 |
def call(self): |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
72 |
params = dict(self._cw.form) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
73 |
self.clean_params(params) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
74 |
basepath = self._cw.relative_path(includeparams=False) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
75 |
w = self.w |
0 | 76 |
w(u'<div class="pagination">') |
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
77 |
w(u'%s ' % self.previous_link(basepath, params)) |
5615
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
78 |
w(u'<select onchange="javascript: document.location=this.options[this.selectedIndex].value">') |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
79 |
for option in self.iter_page_links(basepath, params): |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
80 |
w(option) |
cfa9a776d99a
[navigation] when there are to much results, use a <select> based page navigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
81 |
w(u'</select>') |
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
82 |
w(u' %s' % self.next_link(basepath, params)) |
0 | 83 |
w(u'</div>') |
1657
14e95f7aa033
delete-trailing-whitespaces, add page_size argument to .paginate
sylvain.thenault@logilab.fr
parents:
873
diff
changeset
|
84 |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
85 |
|
0 | 86 |
class SortedNavigation(NavigationComponent): |
87 |
"""sorted navigation apply if navigation is needed (according to page size) |
|
88 |
and if the result set is sorted |
|
89 |
""" |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
692
diff
changeset
|
90 |
__select__ = paginated_rset() & sorted_rset() |
1657
14e95f7aa033
delete-trailing-whitespaces, add page_size argument to .paginate
sylvain.thenault@logilab.fr
parents:
873
diff
changeset
|
91 |
|
0 | 92 |
# number of considered chars to build page links |
93 |
nb_chars = 5 |
|
1657
14e95f7aa033
delete-trailing-whitespaces, add page_size argument to .paginate
sylvain.thenault@logilab.fr
parents:
873
diff
changeset
|
94 |
|
0 | 95 |
def display_func(self, rset, col, attrname): |
96 |
if attrname is not None: |
|
97 |
def index_display(row): |
|
3751
ff404cef5244
take care to outer joins
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
98 |
if not rset[row][col]: # outer join |
ff404cef5244
take care to outer joins
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
99 |
return u'' |
0 | 100 |
entity = rset.get_entity(row, col) |
101 |
return entity.printable_value(attrname, format='text/plain') |
|
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
102 |
elif self._cw.vreg.schema.eschema(rset.description[0][col]).final: |
0 | 103 |
def index_display(row): |
104 |
return unicode(rset[row][col]) |
|
105 |
else: |
|
106 |
def index_display(row): |
|
107 |
return rset.get_entity(row, col).view('text') |
|
108 |
return index_display |
|
1657
14e95f7aa033
delete-trailing-whitespaces, add page_size argument to .paginate
sylvain.thenault@logilab.fr
parents:
873
diff
changeset
|
109 |
|
0 | 110 |
def call(self): |
111 |
"""displays links to navigate accross pages of a result set |
|
112 |
||
113 |
Displayed result is done according to a variable on which the sort |
|
114 |
is done, and looks like: |
|
115 |
[ana - cro] | [cro - ghe] | ... | [tim - zou] |
|
116 |
""" |
|
117 |
w = self.w |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
118 |
rset = self.cw_rset |
0 | 119 |
page_size = self.page_size |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
120 |
rschema = self._cw.vreg.schema.rschema |
0 | 121 |
# attrname = the name of attribute according to which the sort |
122 |
# is done if any |
|
123 |
for sorterm in rset.syntax_tree().children[0].orderby: |
|
124 |
if isinstance(sorterm.term, Constant): |
|
125 |
col = sorterm.term.value - 1 |
|
126 |
index_display = self.display_func(rset, col, None) |
|
127 |
break |
|
128 |
var = sorterm.term.get_nodes(VariableRef)[0].variable |
|
129 |
col = None |
|
130 |
for ref in var.references(): |
|
131 |
rel = ref.relation() |
|
132 |
if rel is None: |
|
133 |
continue |
|
134 |
attrname = rel.r_type |
|
5944
b962dff47c36
[ftirank] when ordered by fti rank, we don't want page navigation. Anyway, sorted nav component shouldn't consider has_text relation.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
135 |
if attrname in ('is', 'has_text'): |
0 | 136 |
continue |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3018
diff
changeset
|
137 |
if not rschema(attrname).final: |
0 | 138 |
col = var.selected_index() |
139 |
attrname = None |
|
140 |
if col is None: |
|
141 |
# final relation or not selected non final relation |
|
142 |
if var is rel.children[0]: |
|
143 |
relvar = rel.children[1].children[0].get_nodes(VariableRef)[0] |
|
144 |
else: |
|
145 |
relvar = rel.children[0].variable |
|
146 |
col = relvar.selected_index() |
|
147 |
if col is not None: |
|
148 |
break |
|
149 |
else: |
|
150 |
# no relation but maybe usable anyway if selected |
|
151 |
col = var.selected_index() |
|
152 |
attrname = None |
|
153 |
if col is not None: |
|
154 |
index_display = self.display_func(rset, col, attrname) |
|
155 |
break |
|
156 |
else: |
|
157 |
# nothing usable found, use the first column |
|
158 |
index_display = self.display_func(rset, 0, None) |
|
159 |
blocklist = [] |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
160 |
params = dict(self._cw.form) |
0 | 161 |
self.clean_params(params) |
162 |
start = 0 |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
163 |
basepath = self._cw.relative_path(includeparams=False) |
0 | 164 |
while start < rset.rowcount: |
165 |
stop = min(start + page_size - 1, rset.rowcount - 1) |
|
166 |
cell = self.format_link_content(index_display(start), index_display(stop)) |
|
167 |
blocklist.append(self.page_link(basepath, params, start, stop, cell)) |
|
168 |
start = stop + 1 |
|
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
169 |
self.write_links(basepath, params, blocklist) |
0 | 170 |
|
171 |
def format_link_content(self, startstr, stopstr): |
|
172 |
text = u'%s - %s' % (startstr.lower()[:self.nb_chars], |
|
173 |
stopstr.lower()[:self.nb_chars]) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2259
diff
changeset
|
174 |
return xml_escape(text) |
0 | 175 |
|
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
176 |
def write_links(self, basepath, params, blocklist): |
0 | 177 |
self.w(u'<div class="pagination">') |
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
178 |
self.w(u'%s ' % self.previous_link(basepath, params)) |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2650
diff
changeset
|
179 |
self.w(u'[ %s ]' % u' | '.join(blocklist)) |
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2996
diff
changeset
|
180 |
self.w(u' %s' % self.next_link(basepath, params)) |
0 | 181 |
self.w(u'</div>') |
182 |
||
183 |
||
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
184 |
from cubicweb.interfaces import IPrevNext |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
185 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
186 |
class IPrevNextAdapter(EntityAdapter): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
187 |
"""interface for entities which can be linked to a previous and/or next |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
188 |
entity |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
189 |
""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
190 |
__regid__ = 'IPrevNext' |
5895
6a3f776292a5
[selectors]Â avoid spurious warning when using implements by design
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5819
diff
changeset
|
191 |
__select__ = implements(IPrevNext, warn=False) # XXX for bw compat, else should be abstract |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
192 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
193 |
@implements_adapter_compat('IPrevNext') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
194 |
def next_entity(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
195 |
"""return the 'next' entity""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
196 |
raise NotImplementedError |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
197 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
198 |
@implements_adapter_compat('IPrevNext') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
199 |
def previous_entity(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
200 |
"""return the 'previous' entity""" |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
201 |
raise NotImplementedError |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
202 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
203 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
204 |
class NextPrevNavigationComponent(EntityCtxComponent): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
205 |
__regid__ = 'prevnext' |
0 | 206 |
# register msg not generated since no entity implements IPrevNext in cubicweb |
207 |
# itself |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
208 |
help = _('ctxcomponents_prevnext_description') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
209 |
__select__ = EntityCtxComponent.__select__ & adaptable('IPrevNext') |
0 | 210 |
context = 'navbottom' |
211 |
order = 10 |
|
5966
0677cfb28ad2
[iprevnext] implements cell_call to remove warning when displayed in the main content zone
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5944
diff
changeset
|
212 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
213 |
def init_rendering(self): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
214 |
adapter = self.entity.cw_adapt_to('IPrevNext') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
215 |
self.previous = adapter.previous_entity() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
216 |
self.next = adapter.next_entity() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
217 |
if not (self.previous or self.next): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
218 |
raise EmptyComponent() |
5966
0677cfb28ad2
[iprevnext] implements cell_call to remove warning when displayed in the main content zone
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5944
diff
changeset
|
219 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
220 |
def render_body(self, w): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
221 |
w(u'<div class="prevnext">') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
222 |
self.prevnext(w) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
223 |
w(u'</div>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
224 |
w(u'<div class="clear"></div>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
225 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
226 |
def prevnext(self, w): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
227 |
if self.previous: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
228 |
self.prevnext_entity(w, self.previous, 'prev') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
229 |
if self.next: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
230 |
self.prevnext_entity(w, self.next, 'next') |
0 | 231 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
232 |
def prevnext_entity(self, w, entity, type): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
233 |
textsize = self._cw.property_value('navigation.short-line-size') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
234 |
if type == 'prev': |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
235 |
title = self._cw._('i18nprevnext_previous') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
236 |
icon = u'<< ' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
237 |
cssclass = u'previousEntity left' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
238 |
else: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
239 |
title = self._cw._('i18nprevnext_next') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
240 |
icon = u'>> ' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
241 |
cssclass = u'nextEntity right' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
242 |
self.prevnext_div(w, type, cssclass, entity.absolute_url(), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
243 |
title, icon + xml_escape(cut(entity.dc_title(), textsize))) |
1657
14e95f7aa033
delete-trailing-whitespaces, add page_size argument to .paginate
sylvain.thenault@logilab.fr
parents:
873
diff
changeset
|
244 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
245 |
def prevnext_div(self, w, type, cssclass, url, title, content): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
246 |
w(u'<div class="%s">' % cssclass) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
247 |
w(u'<a href="%s" title="%s">%s</a>' % (xml_escape(url), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
248 |
xml_escape(title), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
249 |
content)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
250 |
w(u'</div>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
251 |
self._cw.html_headers.add_raw('<link rel="%s" href="%s" />' % ( |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6007
diff
changeset
|
252 |
type, xml_escape(url))) |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
253 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
254 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
255 |
def do_paginate(view, rset=None, w=None, show_all_option=True, page_size=None): |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
256 |
"""write pages index in w stream (default to view.w) and then limit the result |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
257 |
set (default to view.rset) to the currently displayed page |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
258 |
""" |
4265
0912f111b028
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
259 |
req = view._cw |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
260 |
if rset is None: |
4265
0912f111b028
3.6 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
261 |
rset = view.cw_rset |
4357
ef8e20bfa287
case where 'w' argument is None should be handled in do_paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4336
diff
changeset
|
262 |
if w is None: |
ef8e20bfa287
case where 'w' argument is None should be handled in do_paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4336
diff
changeset
|
263 |
w = view.w |
4252 | 264 |
nav = req.vreg['components'].select_or_none( |
5616
859225caf375
[navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5615
diff
changeset
|
265 |
'navigation', req, rset=rset, page_size=page_size, view=view) |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
266 |
if nav: |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
267 |
if w is None: |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
268 |
w = view.w |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
269 |
# get boundaries before component rendering |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
270 |
start, stop = nav.page_boundaries() |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
271 |
nav.render(w=w) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
272 |
params = dict(req.form) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
273 |
nav.clean_params(params) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
274 |
# make a link to see them all |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
275 |
if show_all_option: |
5910
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
276 |
basepath = req.relative_path(includeparams=False) |
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
277 |
params['__force_display'] = 1 |
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
278 |
url = nav.page_url(basepath, params) |
5819
1017163825c7
[css] more css rework, need visual test in compat/new modes
katia
parents:
5627
diff
changeset
|
279 |
w(u'<div><a href="%s">%s</a></div>\n' |
5910
432c657ebfec
[facets] fix bug w/ vid in facet's js introduced in 3.9, improve navigation component so that show all link use ajax when called from ajax.
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5895
diff
changeset
|
280 |
% (xml_escape(url), req._('show %s results') % len(rset))) |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
281 |
rset.limit(offset=start, limit=stop-start, inplace=True) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
282 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
283 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
284 |
def paginate(view, show_all_option=True, w=None, page_size=None, rset=None): |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
285 |
"""paginate results if the view is paginable and we're not explictly told to |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
286 |
display everything (by setting __force_display in req.form) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
287 |
""" |
4336 | 288 |
if view.paginable and not view._cw.form.get('__force_display'): |
4357
ef8e20bfa287
case where 'w' argument is None should be handled in do_paginate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4336
diff
changeset
|
289 |
do_paginate(view, rset, w, show_all_option, page_size) |
4244
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
290 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
291 |
# monkey patch base View class to add a .paginate([...]) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
292 |
# method to be called to write pages index in the view and then limit the result |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
293 |
# set to the current page |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
294 |
from cubicweb.view import View |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
295 |
View.do_paginate = do_paginate |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
296 |
View.paginate = paginate |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
297 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
298 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
299 |
#@deprecated (see below) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
300 |
def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False, |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
301 |
show_all_option=True, page_size=None): |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
302 |
if not (forcedisplay or req.form.get('__force_display') is not None): |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
303 |
do_paginate(self, rset, w, show_all_option, page_size) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
304 |
|
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
305 |
View.pagination = deprecated('[3.2] .pagination is deprecated, use paginate')( |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
306 |
limit_rset_using_paged_nav) |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
307 |
limit_rset_using_paged_nav = deprecated('[3.6] limit_rset_using_paged_nav is deprecated, use do_paginate')( |
2c3de1953d00
rename need_navigation into paginable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4213
diff
changeset
|
308 |
limit_rset_using_paged_nav) |