author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 24 Sep 2010 12:53:56 +0200 | |
branch | stable |
changeset 6335 | d13d488a453e |
parent 6280 | e220f8b85f88 |
child 6333 | e3994fcc21c3 |
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
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:
5389
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
18 |
"""abstract component class and base components definition for CubicWeb web |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
19 |
client |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
20 |
""" |
0 | 21 |
|
22 |
__docformat__ = "restructuredtext en" |
|
2259 | 23 |
_ = unicode |
0 | 24 |
|
681
7cb402fa3958
use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents:
670
diff
changeset
|
25 |
from logilab.common.deprecation import class_renamed |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2259
diff
changeset
|
26 |
from logilab.mtconverter import xml_escape |
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
27 |
|
799
ad129d374ee2
fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents:
747
diff
changeset
|
28 |
from cubicweb import role |
5940
0e3ae19b181a
[uilib] refactor json_dumps code organization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5910
diff
changeset
|
29 |
from cubicweb.utils import json_dumps |
6248
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
30 |
from cubicweb.uilib import js |
2819
b864288fd316
remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
31 |
from cubicweb.view import Component |
655 | 32 |
from cubicweb.selectors import ( |
33 |
paginated_rset, one_line_rset, primary_view, match_context_prop, |
|
2819
b864288fd316
remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
34 |
partial_has_related_entities) |
0 | 35 |
|
36 |
||
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
37 |
class EntityVComponent(Component): |
0 | 38 |
"""abstract base class for additinal components displayed in content |
39 |
headers and footer according to: |
|
1433 | 40 |
|
0 | 41 |
* the displayed entity's type |
42 |
* a context (currently 'header' or 'footer') |
|
43 |
||
44 |
it should be configured using .accepts, .etype, .rtype, .target and |
|
45 |
.context class attributes |
|
46 |
""" |
|
1433 | 47 |
|
0 | 48 |
__registry__ = 'contentnavigation' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
687
diff
changeset
|
49 |
__select__ = one_line_rset() & primary_view() & match_context_prop() |
1433 | 50 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
51 |
cw_property_defs = { |
0 | 52 |
_('visible'): dict(type='Boolean', default=True, |
2237
7e546c3d6ea5
[primary] fix #344249
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1977
diff
changeset
|
53 |
help=_('display the component or not')), |
0 | 54 |
_('order'): dict(type='Int', default=99, |
55 |
help=_('display order of the component')), |
|
3840
2eff4348b1e4
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3750
diff
changeset
|
56 |
_('context'): dict(type='String', default='navtop', |
1433 | 57 |
vocabulary=(_('navtop'), _('navbottom'), |
3840
2eff4348b1e4
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3750
diff
changeset
|
58 |
_('navcontenttop'), _('navcontentbottom'), |
2eff4348b1e4
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3750
diff
changeset
|
59 |
_('ctxtoolbar')), |
0 | 60 |
help=_('context where this component should be displayed')), |
61 |
} |
|
1433 | 62 |
|
3840
2eff4348b1e4
prepare support for a 'context toolbar', used in tracker but will much probably be backported in default primary view. Turn pdfview component into a toolbar element
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3750
diff
changeset
|
63 |
context = 'navcontentbottom' |
1433 | 64 |
|
880 | 65 |
def call(self, view=None): |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
66 |
if self.cw_rset is None: |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
67 |
self.entity_call(self.cw_extra_kwargs.pop('entity')) |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
68 |
else: |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
69 |
self.cell_call(0, 0, view=view) |
529
6e84e93fa7ec
EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents:
330
diff
changeset
|
70 |
|
880 | 71 |
def cell_call(self, row, col, view=None): |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
72 |
self.entity_call(self.cw_rset.get_entity(row, col), view=view) |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
73 |
|
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5624
diff
changeset
|
74 |
def entity_call(self, entity, view=None): |
529
6e84e93fa7ec
EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents:
330
diff
changeset
|
75 |
raise NotImplementedError() |
0 | 76 |
|
1433 | 77 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
78 |
class NavigationComponent(Component): |
0 | 79 |
"""abstract base class for navigation components""" |
3408
c92170fca813
[api] use __regid__ instead of deprecated id
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3023
diff
changeset
|
80 |
__regid__ = 'navigation' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
687
diff
changeset
|
81 |
__select__ = paginated_rset() |
1433 | 82 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
83 |
cw_property_defs = { |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
84 |
_('visible'): dict(type='Boolean', default=True, |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
85 |
help=_('display the component or not')), |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
86 |
} |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
87 |
|
0 | 88 |
page_size_property = 'navigation.page-size' |
89 |
start_param = '__start' |
|
90 |
stop_param = '__stop' |
|
91 |
page_link_templ = u'<span class="slice"><a href="%s" title="%s">%s</a></span>' |
|
92 |
selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>' |
|
93 |
previous_page_link_templ = next_page_link_templ = page_link_templ |
|
3012
97696093ba54
[page nav] display non clickable previous/next page when it does'nt make sense instead of nothing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3010
diff
changeset
|
94 |
no_previous_page_link = u'<<' |
97696093ba54
[page nav] display non clickable previous/next page when it does'nt make sense instead of nothing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3010
diff
changeset
|
95 |
no_next_page_link = u'>>' |
1433 | 96 |
|
1339 | 97 |
def __init__(self, req, rset, **kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
98 |
super(NavigationComponent, self).__init__(req, rset=rset, **kwargs) |
0 | 99 |
self.starting_from = 0 |
100 |
self.total = rset.rowcount |
|
101 |
||
102 |
def get_page_size(self): |
|
103 |
try: |
|
104 |
return self._page_size |
|
105 |
except AttributeError: |
|
3468
b02fa4db2868
[tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
106 |
page_size = self.cw_extra_kwargs.get('page_size') |
822 | 107 |
if page_size is None: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
108 |
if 'page_size' in self._cw.form: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
109 |
page_size = int(self._cw.form['page_size']) |
822 | 110 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
111 |
page_size = self._cw.property_value(self.page_size_property) |
799
ad129d374ee2
fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents:
747
diff
changeset
|
112 |
self._page_size = page_size |
ad129d374ee2
fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents:
747
diff
changeset
|
113 |
return page_size |
0 | 114 |
|
115 |
def set_page_size(self, page_size): |
|
116 |
self._page_size = page_size |
|
1433 | 117 |
|
0 | 118 |
page_size = property(get_page_size, set_page_size) |
1433 | 119 |
|
0 | 120 |
def page_boundaries(self): |
121 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
122 |
stop = int(self._cw.form[self.stop_param]) + 1 |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
123 |
start = int(self._cw.form[self.start_param]) |
0 | 124 |
except KeyError: |
125 |
start, stop = 0, self.page_size |
|
4089
ff92c7d692bf
typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
126 |
if start >= len(self.cw_rset): |
3607
a7c5e62c7e00
don't crash if specified page size is greater than rset size
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3014
diff
changeset
|
127 |
start, stop = 0, self.page_size |
0 | 128 |
self.starting_from = start |
129 |
return start, stop |
|
1433 | 130 |
|
0 | 131 |
def clean_params(self, params): |
132 |
if self.start_param in params: |
|
133 |
del params[self.start_param] |
|
134 |
if self.stop_param in params: |
|
135 |
del params[self.stop_param] |
|
136 |
||
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:
5715
diff
changeset
|
137 |
def page_url(self, path, params, start=None, stop=None): |
4882
4a42d700c52d
[web] stop using deprecated merge_dicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
138 |
params = dict(params) |
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:
5715
diff
changeset
|
139 |
if start is not None: |
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:
5715
diff
changeset
|
140 |
params[self.start_param] = start |
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:
5715
diff
changeset
|
141 |
if stop is not None: |
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:
5715
diff
changeset
|
142 |
params[self.stop_param] = stop |
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:
5426
diff
changeset
|
143 |
view = self.cw_extra_kwargs.get('view') |
859225caf375
[navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
144 |
if view is not None and hasattr(view, 'page_navigation_url'): |
859225caf375
[navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
145 |
url = view.page_navigation_url(self, path, params) |
859225caf375
[navigation] view may implements page_navigation_url to handle them self url generated for pagination
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
146 |
elif path == 'json': |
6248
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
147 |
url = self.ajax_page_url(**params) |
3013
6a40a9a72957
[page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3012
diff
changeset
|
148 |
else: |
3457
0924d0d08d60
[api] __regid__, cw_* and friends
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
149 |
url = self._cw.build_url(path, **params) |
6280
e220f8b85f88
[navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6265
diff
changeset
|
150 |
# XXX hack to avoid opening a new page containing the evaluation of the |
e220f8b85f88
[navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6265
diff
changeset
|
151 |
# js expression on ajax call |
e220f8b85f88
[navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6265
diff
changeset
|
152 |
if url.startswith('javascript:'): |
e220f8b85f88
[navigation] move hack from page_link to page_url so '#1251858: Can't see all the elements when a limited list is shown' if fixed as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6265
diff
changeset
|
153 |
url += '; noop();' |
3013
6a40a9a72957
[page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3012
diff
changeset
|
154 |
return url |
6a40a9a72957
[page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3012
diff
changeset
|
155 |
|
6248
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
156 |
def ajax_page_url(self, **params): |
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
157 |
divid = params.setdefault('divid', 'pageContent') |
6265
27417b8b94ed
[navigation] for rql to the one of the rset being paginated
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6248
diff
changeset
|
158 |
params['rql'] = self.cw_rset.printable_rql() |
6248
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
159 |
return "javascript: $(%s).loadxhtml('json', %s, 'get', 'swap')" % ( |
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
160 |
json_dumps('#'+divid), js.ajaxFuncArgs('view', params)) |
3f89bf00e8ce
[navigation] refactor base navigation component: replace deprecated replacePageChunk js call by loadxhtml, using the magic js object
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5940
diff
changeset
|
161 |
|
0 | 162 |
def page_link(self, path, params, start, stop, content): |
3013
6a40a9a72957
[page nav] json navigation (when coming from a facets restriction for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3012
diff
changeset
|
163 |
url = xml_escape(self.page_url(path, params, start, stop)) |
0 | 164 |
if start == self.starting_from: |
165 |
return self.selected_page_link_templ % (url, content, content) |
|
166 |
return self.page_link_templ % (url, content, content) |
|
167 |
||
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3013
diff
changeset
|
168 |
def previous_link(self, path, params, content='<<', title=_('previous_results')): |
0 | 169 |
start = self.starting_from |
170 |
if not start : |
|
171 |
return self.no_previous_page_link |
|
172 |
start = max(0, start - self.page_size) |
|
173 |
stop = start + self.page_size - 1 |
|
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3013
diff
changeset
|
174 |
url = xml_escape(self.page_url(path, params, start, stop)) |
0 | 175 |
return self.previous_page_link_templ % (url, title, content) |
176 |
||
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3013
diff
changeset
|
177 |
def next_link(self, path, params, content='>>', title=_('next_results')): |
0 | 178 |
start = self.starting_from + self.page_size |
179 |
if start >= self.total: |
|
180 |
return self.no_next_page_link |
|
181 |
stop = start + self.page_size - 1 |
|
3014
62ce5a139b52
[page nav] previous/next page links should also consider url's base path
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3013
diff
changeset
|
182 |
url = xml_escape(self.page_url(path, params, start, stop)) |
0 | 183 |
return self.next_page_link_templ % (url, title, content) |
184 |
||
185 |
||
186 |
class RelatedObjectsVComponent(EntityVComponent): |
|
187 |
"""a section to display some related entities""" |
|
883
44f1aba675de
missing selectors, no more need for relation_possible when using has_related_entities (implied)
sylvain.thenault@logilab.fr
parents:
880
diff
changeset
|
188 |
__select__ = EntityVComponent.__select__ & partial_has_related_entities() |
1433 | 189 |
|
0 | 190 |
vid = 'list' |
1433 | 191 |
|
0 | 192 |
def rql(self): |
655 | 193 |
"""override this method if you want to use a custom rql query""" |
0 | 194 |
return None |
1433 | 195 |
|
529
6e84e93fa7ec
EntityVComponent should now implements cell_call
sylvain.thenault@logilab.fr
parents:
330
diff
changeset
|
196 |
def cell_call(self, row, col, view=None): |
0 | 197 |
rql = self.rql() |
198 |
if rql is None: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
199 |
entity = self.cw_rset.get_entity(row, col) |
799
ad129d374ee2
fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents:
747
diff
changeset
|
200 |
rset = entity.related(self.rtype, role(self)) |
0 | 201 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
202 |
eid = self.cw_rset[row][col] |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4882
diff
changeset
|
203 |
rset = self._cw.execute(self.rql(), {'x': eid}) |
0 | 204 |
if not rset.rowcount: |
205 |
return |
|
206 |
self.w(u'<div class="%s">' % self.div_class()) |
|
3777 | 207 |
self.w(u'<h4>%s</h4>\n' % self._cw._(self.title).capitalize()) |
3750
b7fa3d93640a
display title in the component to avoid relying on view supporting title argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3607
diff
changeset
|
208 |
self.wview(self.vid, rset) |
0 | 209 |
self.w(u'</div>') |
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
210 |
|
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
211 |
|
681
7cb402fa3958
use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents:
670
diff
changeset
|
212 |
VComponent = class_renamed('VComponent', Component, |
7cb402fa3958
use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents:
670
diff
changeset
|
213 |
'VComponent is deprecated, use Component') |
7cb402fa3958
use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents:
670
diff
changeset
|
214 |
SingletonVComponent = class_renamed('SingletonVComponent', Component, |
7cb402fa3958
use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents:
670
diff
changeset
|
215 |
'SingletonVComponent is deprecated, use ' |
7cb402fa3958
use class_renamed, not class_moved
sylvain.thenault@logilab.fr
parents:
670
diff
changeset
|
216 |
'Component and explicit registration control') |