author | Julien Cristau <julien.cristau@logilab.fr> |
Tue, 05 Jan 2016 10:36:17 +0100 | |
changeset 11082 | 0cdd92261c4a |
parent 10903 | da30851f9706 |
permissions | -rw-r--r-- |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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" |
|
10666
7f6b5f023884
[py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10510
diff
changeset
|
23 |
from cubicweb import _ |
0 | 24 |
|
6423
c560f8d9faee
[pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6333
diff
changeset
|
25 |
from warnings import warn |
c560f8d9faee
[pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6333
diff
changeset
|
26 |
|
10713
ec0f96cd7a18
[py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10702
diff
changeset
|
27 |
from six import PY3, add_metaclass, text_type |
10688
fa29f3628a1b
[py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10666
diff
changeset
|
28 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
29 |
from logilab.common.deprecation import class_deprecated, class_renamed, deprecated |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2259
diff
changeset
|
30 |
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
|
31 |
|
6490
34359fbde6ef
[components] add missing imports for code copied/pasted. Forgot to run pylint afterward...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6489
diff
changeset
|
32 |
from cubicweb import Unauthorized, role, target, tags |
34359fbde6ef
[components] add missing imports for code copied/pasted. Forgot to run pylint afterward...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6489
diff
changeset
|
33 |
from cubicweb.schema import display_name |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
34 |
from cubicweb.uilib import js, domid |
7998
9ef285eb20f4
[utils] add a ``js_href`` function to generated proper javascript href
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7991
diff
changeset
|
35 |
from cubicweb.utils import json_dumps, js_href |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
36 |
from cubicweb.view import ReloadableMixIn, Component |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8102
diff
changeset
|
37 |
from cubicweb.predicates import (no_cnx, paginated_rset, one_line_rset, |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
38 |
non_final_entity, partial_relation_possible, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
39 |
partial_has_related_entities) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
40 |
from cubicweb.appobject import AppObject |
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
41 |
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs |
0 | 42 |
|
43 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
44 |
# abstract base class for navigation components ################################ |
1433 | 45 |
|
661
4f61eb8a96b7
properly kill/depreciate component base class, only keep Component
sylvain.thenault@logilab.fr
parents:
659
diff
changeset
|
46 |
class NavigationComponent(Component): |
0 | 47 |
"""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
|
48 |
__regid__ = 'navigation' |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
687
diff
changeset
|
49 |
__select__ = paginated_rset() |
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 = { |
1511
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
52 |
_('visible'): dict(type='Boolean', default=True, |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
53 |
help=_('display the component or not')), |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
54 |
} |
514e4e53a3c7
do not set visible property by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
55 |
|
0 | 56 |
page_size_property = 'navigation.page-size' |
57 |
start_param = '__start' |
|
58 |
stop_param = '__stop' |
|
59 |
page_link_templ = u'<span class="slice"><a href="%s" title="%s">%s</a></span>' |
|
60 |
selected_page_link_templ = u'<span class="selectedSlice"><a href="%s" title="%s">%s</a></span>' |
|
61 |
previous_page_link_templ = next_page_link_templ = page_link_templ |
|
1433 | 62 |
|
1339 | 63 |
def __init__(self, req, rset, **kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
64 |
super(NavigationComponent, self).__init__(req, rset=rset, **kwargs) |
0 | 65 |
self.starting_from = 0 |
66 |
self.total = rset.rowcount |
|
67 |
||
68 |
def get_page_size(self): |
|
69 |
try: |
|
70 |
return self._page_size |
|
71 |
except AttributeError: |
|
3468
b02fa4db2868
[tests] make unittest_viewselectors pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3457
diff
changeset
|
72 |
page_size = self.cw_extra_kwargs.get('page_size') |
822 | 73 |
if page_size is None: |
11082
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
74 |
try: |
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
75 |
page_size = int(self._cw.form.get('page_size')) |
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
76 |
except (ValueError, TypeError): |
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
77 |
# no or invalid value, fall back |
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
78 |
pass |
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
79 |
if page_size is None: |
0cdd92261c4a
[web/component] guard against invalid page_size form parameter
Julien Cristau <julien.cristau@logilab.fr>
parents:
10903
diff
changeset
|
80 |
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
|
81 |
self._page_size = page_size |
ad129d374ee2
fix page_size handling, use abstract_has_related_entities
sylvain.thenault@logilab.fr
parents:
747
diff
changeset
|
82 |
return page_size |
0 | 83 |
|
84 |
def set_page_size(self, page_size): |
|
85 |
self._page_size = page_size |
|
1433 | 86 |
|
0 | 87 |
page_size = property(get_page_size, set_page_size) |
1433 | 88 |
|
0 | 89 |
def page_boundaries(self): |
90 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3408
diff
changeset
|
91 |
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
|
92 |
start = int(self._cw.form[self.start_param]) |
0 | 93 |
except KeyError: |
94 |
start, stop = 0, self.page_size |
|
4089
ff92c7d692bf
typos, api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
95 |
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
|
96 |
start, stop = 0, self.page_size |
0 | 97 |
self.starting_from = start |
98 |
return start, stop |
|
1433 | 99 |
|
0 | 100 |
def clean_params(self, params): |
101 |
if self.start_param in params: |
|
102 |
del params[self.start_param] |
|
103 |
if self.stop_param in params: |
|
104 |
del params[self.stop_param] |
|
105 |
||
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
|
106 |
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
|
107 |
params = dict(params) |
8102
619d41a4c770
[navigation] provide a link back from the full view to the paginated one
Julien Cristau <julien.cristau@logilab.fr>
parents:
8054
diff
changeset
|
108 |
params['__fromnavigation'] = 1 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
url = view.page_navigation_url(self, path, params) |
9587
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
116 |
elif path in ('json', 'ajax'): |
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
117 |
# 'ajax' is the new correct controller, but the old 'json' |
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
118 |
# controller should still be supported |
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
119 |
url = self.ajax_page_url(**params) |
9530
170e1437948d
[web/navigation] use add_onload instead of inline javascript href
Julien Cristau <julien.cristau@logilab.fr>
parents:
8900
diff
changeset
|
120 |
else: |
9587
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
121 |
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
|
122 |
# 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
|
123 |
# 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
|
124 |
if url.startswith('javascript:'): |
6543
66145280a7e6
[js] remove deprecation warnings by using $.noop instead of noop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6490
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
|
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
|
128 |
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
|
129 |
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
|
130 |
params['rql'] = self.cw_rset.printable_rql() |
9587
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
131 |
return js_href("$(%s).loadxhtml(AJAX_PREFIX_URL, %s, 'get', 'swap')" % ( |
0f0199948f93
Backout "[web/navigation] use add_onload instead of inline javascript href"
Julien Cristau <julien.cristau@logilab.fr>
parents:
9536
diff
changeset
|
132 |
json_dumps('#'+divid), js.ajaxFuncArgs('view', params))) |
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
|
133 |
|
0 | 134 |
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
|
135 |
url = xml_escape(self.page_url(path, params, start, stop)) |
0 | 136 |
if start == self.starting_from: |
137 |
return self.selected_page_link_templ % (url, content, content) |
|
138 |
return self.page_link_templ % (url, content, content) |
|
139 |
||
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
140 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
141 |
def prev_icon_url(self): |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
142 |
return xml_escape(self._cw.data_url('go_prev.png')) |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
143 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
144 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
145 |
def next_icon_url(self): |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
146 |
return xml_escape(self._cw.data_url('go_next.png')) |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
147 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
148 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
149 |
def no_previous_page_link(self): |
7326
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
150 |
return (u'<img src="%s" alt="%s" class="prevnext_nogo"/>' % |
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
151 |
(self.prev_icon_url, self._cw._('there is no previous page'))) |
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
152 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
153 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
154 |
def no_next_page_link(self): |
7326
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
155 |
return (u'<img src="%s" alt="%s" class="prevnext_nogo"/>' % |
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
156 |
(self.next_icon_url, self._cw._('there is no next page'))) |
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
157 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
158 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
159 |
def no_content_prev_link(self): |
7326
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
160 |
return (u'<img src="%s" alt="%s" class="prevnext"/>' % ( |
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
161 |
(self.prev_icon_url, self._cw._('no content prev link')))) |
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
162 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
163 |
@property |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
164 |
def no_content_next_link(self): |
7326
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
165 |
return (u'<img src="%s" alt="%s" class="prevnext"/>' % |
6c603d0fb2c7
[component|i18n] give imgs an alt attribute, refresh i18n po files
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7323
diff
changeset
|
166 |
(self.next_icon_url, self._cw._('no content next link'))) |
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
167 |
|
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
168 |
def previous_link(self, path, params, content=None, title=_('previous_results')): |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
169 |
if not content: |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
170 |
content = self.no_content_prev_link |
0 | 171 |
start = self.starting_from |
172 |
if not start : |
|
173 |
return self.no_previous_page_link |
|
174 |
start = max(0, start - self.page_size) |
|
175 |
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
|
176 |
url = xml_escape(self.page_url(path, params, start, stop)) |
8052
fbeb82fe45a4
[prev/next] properly translate previous/next links' title, closes #2072158
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
177 |
return self.previous_page_link_templ % (url, self._cw._(title), content) |
0 | 178 |
|
7323
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
179 |
def next_link(self, path, params, content=None, title=_('next_results')): |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
180 |
if not content: |
53f38d39287f
[nav component/cosmetics] have nice looking arrows insteads of << / >>
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6987
diff
changeset
|
181 |
content = self.no_content_next_link |
0 | 182 |
start = self.starting_from + self.page_size |
183 |
if start >= self.total: |
|
184 |
return self.no_next_page_link |
|
185 |
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
|
186 |
url = xml_escape(self.page_url(path, params, start, stop)) |
8052
fbeb82fe45a4
[prev/next] properly translate previous/next links' title, closes #2072158
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
187 |
return self.next_page_link_templ % (url, self._cw._(title), content) |
0 | 188 |
|
189 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
190 |
# new contextual components system ############################################# |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
191 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
192 |
def override_ctx(cls, **kwargs): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
193 |
cwpdefs = cls.cw_property_defs.copy() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
194 |
cwpdefs['context'] = cwpdefs['context'].copy() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
195 |
cwpdefs['context'].update(kwargs) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
196 |
return cwpdefs |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
197 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
198 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
199 |
class EmptyComponent(Exception): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
200 |
"""some selectable component has actually no content and should not be |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
201 |
rendered |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
202 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
203 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
204 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
205 |
class Link(object): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
206 |
"""a link to a view or action in the ui. |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
207 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
208 |
Use this rather than `cw.web.htmlwidgets.BoxLink`. |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
209 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
210 |
Note this class could probably be avoided with a proper DOM on the server |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
211 |
side. |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
212 |
""" |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
213 |
newstyle = True |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
214 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
215 |
def __init__(self, href, label, **attrs): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
216 |
self.href = href |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
217 |
self.label = label |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
218 |
self.attrs = attrs |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
219 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
220 |
def __unicode__(self): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
221 |
return tags.a(self.label, href=self.href, **self.attrs) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
222 |
|
10713
ec0f96cd7a18
[py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10702
diff
changeset
|
223 |
if PY3: |
ec0f96cd7a18
[py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10702
diff
changeset
|
224 |
__str__ = __unicode__ |
ec0f96cd7a18
[py3k] __unicode__ and __str__
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10702
diff
changeset
|
225 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
226 |
def render(self, w): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
227 |
w(tags.a(self.label, href=self.href, **self.attrs)) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
228 |
|
10044
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
229 |
def __repr__(self): |
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
230 |
return '<%s: href=%r label=%r %r>' % (self.__class__.__name__, |
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
231 |
self.href, self.label, self.attrs) |
5907c2b0acd7
[component] give Links a __repr__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10040
diff
changeset
|
232 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
233 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
234 |
class Separator(object): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
235 |
"""a menu separator. |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
236 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
237 |
Use this rather than `cw.web.htmlwidgets.BoxSeparator`. |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
238 |
""" |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
239 |
newstyle = True |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
240 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
241 |
def render(self, w): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
242 |
w(u'<hr class="boxSeparator"/>') |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
243 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
244 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
245 |
def _bwcompatible_render_item(w, item): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
246 |
if hasattr(item, 'render'): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
247 |
if getattr(item, 'newstyle', False): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
248 |
if isinstance(item, Separator): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
249 |
w(u'</ul>') |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
250 |
item.render(w) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
251 |
w(u'<ul>') |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
252 |
else: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
253 |
w(u'<li>') |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
254 |
item.render(w) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
255 |
w(u'</li>') |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
256 |
else: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
257 |
item.render(w) # XXX displays <li> by itself |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
258 |
else: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
259 |
w(u'<li>%s</li>' % item) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
260 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
261 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
262 |
class Layout(Component): |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
263 |
__regid__ = 'component_layout' |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
264 |
__abstract__ = True |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
265 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
266 |
def init_rendering(self): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
267 |
"""init view for rendering. Return true if we should go on, false |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
268 |
if we should stop now. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
269 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
270 |
view = self.cw_extra_kwargs['view'] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
271 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
272 |
view.init_rendering() |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8190
diff
changeset
|
273 |
except Unauthorized as ex: |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
274 |
self.warning("can't render %s: %s", view, ex) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
275 |
return False |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
276 |
except EmptyComponent: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
277 |
return False |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
278 |
return True |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
279 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
280 |
|
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
281 |
class LayoutableMixIn(object): |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
282 |
layout_id = None # to be defined in concret class |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
283 |
layout_args = {} |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
284 |
|
10006
8391bf718485
remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9915
diff
changeset
|
285 |
def layout_render(self, w, **kwargs): |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
286 |
getlayout = self._cw.vreg['components'].select |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
287 |
layout = getlayout(self.layout_id, self._cw, **self.layout_select_args()) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
288 |
layout.render(w) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
289 |
|
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
290 |
def layout_select_args(self): |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
291 |
args = dict(rset=self.cw_rset, row=self.cw_row, col=self.cw_col, |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
292 |
view=self) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
293 |
args.update(self.layout_args) |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
294 |
return args |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
295 |
|
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
296 |
|
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
297 |
class CtxComponent(LayoutableMixIn, AppObject): |
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
298 |
"""base class for contextual components. The following contexts are |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
299 |
predefined: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
300 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
301 |
* boxes: 'left', 'incontext', 'right' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
302 |
* section: 'navcontenttop', 'navcontentbottom', 'navtop', 'navbottom' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
303 |
* other: 'ctxtoolbar' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
304 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
305 |
The 'incontext', 'navcontenttop', 'navcontentbottom' and 'ctxtoolbar' |
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
306 |
contexts are handled by the default primary view, others by the default main |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
307 |
template. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
308 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
309 |
All subclasses may not support all those contexts (for instance if it can't |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
310 |
be displayed as box, or as a toolbar icon). You may restrict allowed context |
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
311 |
as follows: |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
312 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
313 |
.. sourcecode:: python |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
314 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
315 |
class MyComponent(CtxComponent): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
316 |
cw_property_defs = override_ctx(CtxComponent, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
317 |
vocabulary=[list of contexts]) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
318 |
context = 'my default context' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
319 |
|
6580
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
320 |
You can configure a component's default context by simply giving an |
798200432f50
some docstrings
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6553
diff
changeset
|
321 |
appropriate value to the `context` class attribute, as seen above. |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
322 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
323 |
__registry__ = 'ctxcomponents' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
324 |
__select__ = ~no_cnx() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
325 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
326 |
categories_in_order = () |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
327 |
cw_property_defs = { |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
328 |
_('visible'): dict(type='Boolean', default=True, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
329 |
help=_('display the box or not')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
330 |
_('order'): dict(type='Int', default=99, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
331 |
help=_('display order of the box')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
332 |
_('context'): dict(type='String', default='left', |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
333 |
vocabulary=(_('left'), _('incontext'), _('right'), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
334 |
_('navtop'), _('navbottom'), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
335 |
_('navcontenttop'), _('navcontentbottom'), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
336 |
_('ctxtoolbar')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
337 |
help=_('context where this component should be displayed')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
338 |
} |
6423
c560f8d9faee
[pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6333
diff
changeset
|
339 |
visible = True |
c560f8d9faee
[pre 3.10 compat] if CtxComponent as a call() method, emit a deprecation warning but use it. Also ensure default value on class for visible and order, and define wview for bw compat as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6333
diff
changeset
|
340 |
order = 0 |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
341 |
context = 'left' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
342 |
contextual = False |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
343 |
title = None |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
344 |
layout_id = 'component_layout' |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
345 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
346 |
def render(self, w, **kwargs): |
10006
8391bf718485
remove most 3.10 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9915
diff
changeset
|
347 |
self.layout_render(w, **kwargs) |
6907
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
348 |
|
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
349 |
def layout_select_args(self): |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
350 |
args = super(CtxComponent, self).layout_select_args() |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
351 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
352 |
# XXX ensure context is given when the component is reloaded through |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
353 |
# ajax |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
354 |
args['context'] = self.cw_extra_kwargs['context'] |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
355 |
except KeyError: |
7991
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
356 |
args['context'] = self.cw_propval('context') |
dcc5a4d48122
[web component architecture] extract LayoutableMixIn from components
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
357 |
return args |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
358 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
359 |
def init_rendering(self): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
360 |
"""init rendering callback: that's the good time to check your component |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
361 |
has some content to display. If not, you can still raise |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
362 |
:exc:`EmptyComponent` to inform it should be skipped. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
363 |
|
10510
51321946da37
Spelling fixes in comments and docstrings
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10075
diff
changeset
|
364 |
Also, :exc:`Unauthorized` will be caught, logged, then the component |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
365 |
will be skipped. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
366 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
367 |
self.items = [] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
368 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
369 |
@property |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
370 |
def domid(self): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
371 |
"""return the HTML DOM identifier for this component""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
372 |
return domid(self.__regid__) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
373 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
374 |
@property |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
375 |
def cssclass(self): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
376 |
"""return the CSS class name for this component""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
377 |
return domid(self.__regid__) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
378 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
379 |
def render_title(self, w): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
380 |
"""return the title for this component""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
381 |
if self.title: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
382 |
w(self._cw._(self.title)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
383 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
384 |
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:
6140
diff
changeset
|
385 |
"""return the body (content) for this component""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
386 |
raise NotImplementedError() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
387 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
388 |
def render_items(self, w, items=None, klass=u'boxListing'): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
389 |
if items is None: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
390 |
items = self.items |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
391 |
assert items |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
392 |
w(u'<ul class="%s">' % klass) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
393 |
for item in items: |
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
394 |
_bwcompatible_render_item(w, item) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
395 |
w(u'</ul>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
396 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
397 |
def append(self, item): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
398 |
self.items.append(item) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
399 |
|
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
400 |
def action_link(self, action): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
401 |
return self.link(self._cw._(action.title), action.url()) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
402 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
403 |
def link(self, title, url, **kwargs): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
404 |
if self._cw.selected(url): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
405 |
try: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
406 |
kwargs['klass'] += ' selected' |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
407 |
except KeyError: |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
408 |
kwargs['klass'] = 'selected' |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
409 |
return Link(url, title, **kwargs) |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
410 |
|
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
411 |
def separator(self): |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
412 |
return Separator() |
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
413 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
414 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
415 |
class EntityCtxComponent(CtxComponent): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
416 |
"""base class for boxes related to a single entity""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
417 |
__select__ = CtxComponent.__select__ & non_final_entity() & one_line_rset() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
418 |
context = 'incontext' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
419 |
contextual = True |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
420 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
421 |
def __init__(self, *args, **kwargs): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
422 |
super(EntityCtxComponent, self).__init__(*args, **kwargs) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
423 |
try: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
424 |
entity = kwargs['entity'] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
425 |
except KeyError: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
426 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
427 |
self.entity = entity |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
428 |
|
6907
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
429 |
def layout_select_args(self): |
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
430 |
args = super(EntityCtxComponent, self).layout_select_args() |
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
431 |
args['entity'] = self.entity |
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
432 |
return args |
449e5b46ed3d
[component] refactor layout retrieval to handle case where we've an entity without rset properly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6800
diff
changeset
|
433 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
434 |
@property |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
435 |
def domid(self): |
10702
f94c812c3669
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
436 |
return domid(self.__regid__) + text_type(self.entity.eid) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
437 |
|
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
438 |
def lazy_view_holder(self, w, entity, oid, registry='views'): |
9700 | 439 |
"""add a holder and return a URL that may be used to replace this |
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
440 |
holder by the html generate by the view specified by registry and |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
441 |
identifier. Registry defaults to 'views'. |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
442 |
""" |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
443 |
holderid = '%sHolder' % self.domid |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
444 |
w(u'<div id="%s"></div>' % holderid) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
445 |
params = self.cw_extra_kwargs.copy() |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
446 |
params.pop('view', None) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
447 |
params.pop('entity', None) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
448 |
form = params.pop('formparams', {}) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
449 |
if entity.has_eid(): |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
450 |
eid = entity.eid |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
451 |
else: |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
452 |
eid = None |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8732
diff
changeset
|
453 |
form['etype'] = entity.cw_etype |
6924
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
454 |
form['tempEid'] = entity.eid |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
455 |
args = [json_dumps(x) for x in (registry, oid, eid, params)] |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
456 |
return self._cw.ajax_replace_url( |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
457 |
holderid, fname='render', arg=args, **form) |
b88221afe491
[js utils] backport some generic code from comments cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6907
diff
changeset
|
458 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
459 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
460 |
# high level abstract classes ################################################## |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
461 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
462 |
class RQLCtxComponent(CtxComponent): |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
463 |
"""abstract box for boxes displaying the content of a rql query not related |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
464 |
to the current result set. |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
465 |
|
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
466 |
Notice that this class's init_rendering implemention is overwriting context |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
467 |
result set (eg `cw_rset`) with the result set returned by execution of |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
468 |
`to_display_rql()`. |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
469 |
""" |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
470 |
rql = None |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
471 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
472 |
def to_display_rql(self): |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
473 |
"""return arguments to give to self._cw.execute, as a tuple, to build |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
474 |
the result set to be displayed by this box. |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
475 |
""" |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
476 |
assert self.rql is not None, self.__regid__ |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
477 |
return (self.rql,) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
478 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
479 |
def init_rendering(self): |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
480 |
super(RQLCtxComponent, self).init_rendering() |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
481 |
self.cw_rset = self._cw.execute(*self.to_display_rql()) |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
482 |
if not self.cw_rset: |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
483 |
raise EmptyComponent() |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
484 |
|
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
485 |
def render_body(self, w): |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
486 |
rset = self.cw_rset |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
487 |
if len(rset[0]) == 2: |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
488 |
items = [] |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
489 |
for i, (eid, label) in enumerate(rset): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
490 |
entity = rset.get_entity(i, 0) |
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
491 |
items.append(self.link(label, entity.absolute_url())) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
492 |
else: |
6800
3f3d576b87d9
[web action] refactor box menu handling, fixing #1401943 on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6777
diff
changeset
|
493 |
items = [self.link(e.dc_title(), e.absolute_url()) |
6777
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
494 |
for e in rset.entities()] |
1d423b7aa6c9
[ctxcomponents] RQLCtxComponent: refactor init_rendering/render_body to ease overriding
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6743
diff
changeset
|
495 |
self.render_items(w, items) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
496 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
497 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
498 |
class EditRelationMixIn(ReloadableMixIn): |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
499 |
|
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
500 |
def box_item(self, entity, etarget, fname, label): |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
501 |
"""builds HTML link to edit relation between `entity` and `etarget`""" |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
502 |
args = {role(self) : entity.eid, target(self): etarget.eid} |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
503 |
# for each target, provide a link to edit the relation |
9915
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
504 |
jscall = js.cw.utils.callAjaxFuncThenReload(fname, |
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
505 |
self.rtype, |
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
506 |
args['subject'], |
020d2e453e6f
[web/component] move unicode() call around
Julien Cristau <julien.cristau@logilab.fr>
parents:
9914
diff
changeset
|
507 |
args['object']) |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
508 |
return u'[<a href="javascript: %s" class="action">%s</a>] %s' % ( |
10702
f94c812c3669
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
509 |
xml_escape(text_type(jscall)), label, etarget.view('incontext')) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
510 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
511 |
def related_boxitems(self, entity): |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
512 |
return [self.box_item(entity, etarget, 'delete_relation', u'-') |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
513 |
for etarget in self.related_entities(entity)] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
514 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
515 |
def related_entities(self, entity): |
6151
f910c60b84ff
[new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
516 |
return entity.related(self.rtype, role(self), entities=True) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
517 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
518 |
def unrelated_boxitems(self, entity): |
9784
790956c311ef
EditRelationMixIn: stop using user_rql_callback
Julien Cristau <julien.cristau@logilab.fr>
parents:
9700
diff
changeset
|
519 |
return [self.box_item(entity, etarget, 'add_relation', u'+') |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
520 |
for etarget in self.unrelated_entities(entity)] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
521 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
522 |
def unrelated_entities(self, entity): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
523 |
"""returns the list of unrelated entities, using the entity's |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
524 |
appropriate vocabulary function |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
525 |
""" |
10702
f94c812c3669
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
526 |
skip = set(text_type(e.eid) for e in entity.related(self.rtype, role(self), |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
527 |
entities=True)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
528 |
skip.add(None) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
529 |
skip.add(INTERNAL_FIELD_VALUE) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
530 |
filteretype = getattr(self, 'etype', None) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
531 |
entities = [] |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
532 |
form = self._cw.vreg['forms'].select('edition', self._cw, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
533 |
rset=self.cw_rset, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
534 |
row=self.cw_row or 0) |
6151
f910c60b84ff
[new components] fix dumb name error
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
535 |
field = form.field_by_name(self.rtype, role(self), entity.e_schema) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
536 |
for _, eid in field.vocabulary(form): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
537 |
if eid not in skip: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
538 |
entity = self._cw.entity_from_eid(eid) |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8732
diff
changeset
|
539 |
if filteretype is None or entity.cw_etype == filteretype: |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
540 |
entities.append(entity) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
541 |
return entities |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
542 |
|
6553 | 543 |
# XXX should be a view usable using uicfg |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
544 |
class EditRelationCtxComponent(EditRelationMixIn, EntityCtxComponent): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
545 |
"""base class for boxes which let add or remove entities linked by a given |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
546 |
relation |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
547 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
548 |
subclasses should define at least id, rtype and target class attributes. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
549 |
""" |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
550 |
# to be defined in concrete classes |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
551 |
rtype = None |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
552 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
553 |
def render_title(self, w): |
6547
6be127941760
[new components] render_title must write title, not return it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6543
diff
changeset
|
554 |
w(display_name(self._cw, self.rtype, role(self), |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8732
diff
changeset
|
555 |
context=self.entity.cw_etype)) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
556 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
557 |
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:
6140
diff
changeset
|
558 |
self._cw.add_js('cubicweb.ajax.js') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
559 |
related = self.related_boxitems(self.entity) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
560 |
unrelated = self.unrelated_boxitems(self.entity) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
561 |
self.items.extend(related) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
562 |
if related and unrelated: |
6550
8c6a0f6bba3b
[boxes] use a new separator instead of clumsy htmlwidget's one which close and reopen the <ul> (loosing any list class on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6548
diff
changeset
|
563 |
self.items.append(u'<hr class="boxSeparator"/>') |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
564 |
self.items.extend(unrelated) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
565 |
self.render_items(w) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
566 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
567 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
568 |
class AjaxEditRelationCtxComponent(EntityCtxComponent): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
569 |
__select__ = EntityCtxComponent.__select__ & ( |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
570 |
partial_relation_possible(action='add') | partial_has_related_entities()) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
571 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
572 |
# view used to display related entties |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
573 |
item_vid = 'incontext' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
574 |
# values separator when multiple values are allowed |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
575 |
separator = ',' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
576 |
# msgid of the message to display when some new relation has been added/removed |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
577 |
added_msg = None |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
578 |
removed_msg = None |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
579 |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
580 |
# to be defined in concrete classes |
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7536
diff
changeset
|
581 |
rtype = role = target_etype = None |
10903
da30851f9706
spelling: *aly → *ally
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10713
diff
changeset
|
582 |
# class attributes below *must* be set in concrete classes (additionally to |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
583 |
# rtype / role [/ target_etype]. They should correspond to js_* methods on |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
584 |
# the json controller |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
585 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
586 |
# function(eid) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
587 |
# -> expected to return a list of values to display as input selector |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
588 |
# vocabulary |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
589 |
fname_vocabulary = None |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
590 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
591 |
# function(eid, value) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
592 |
# -> handle the selector's input (eg create necessary entities and/or |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
593 |
# relations). If the relation is multiple, you'll get a list of value, else |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
594 |
# a single string value. |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
595 |
fname_validate = None |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
596 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
597 |
# function(eid, linked entity eid) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
598 |
# -> remove the relation |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
599 |
fname_remove = None |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
600 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
601 |
def __init__(self, *args, **kwargs): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
602 |
super(AjaxEditRelationCtxComponent, self).__init__(*args, **kwargs) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
603 |
self.rdef = self.entity.e_schema.rdef(self.rtype, self.role, self.target_etype) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
604 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
605 |
def render_title(self, w): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
606 |
w(self.rdef.rtype.display_name(self._cw, self.role, |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8732
diff
changeset
|
607 |
context=self.entity.cw_etype)) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
608 |
|
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
609 |
def add_js_css(self): |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
610 |
self._cw.add_js(('jquery.ui.js', 'cubicweb.widgets.js')) |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
611 |
self._cw.add_js(('cubicweb.ajax.js', 'cubicweb.ajax.box.js')) |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
612 |
self._cw.add_css('jquery.ui.css') |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
613 |
return True |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
614 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
615 |
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:
6140
diff
changeset
|
616 |
req = self._cw |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
617 |
entity = self.entity |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
618 |
related = entity.related(self.rtype, self.role) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
619 |
if self.role == 'subject': |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
620 |
mayadd = self.rdef.has_perm(req, 'add', fromeid=entity.eid) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
621 |
else: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
622 |
mayadd = self.rdef.has_perm(req, 'add', toeid=entity.eid) |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
623 |
js_css_added = False |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
624 |
if mayadd: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
625 |
js_css_added = self.add_js_css() |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
626 |
_ = req._ |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
627 |
if related: |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
628 |
maydel = None |
6452
6b6a2fa28069
[ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6448
diff
changeset
|
629 |
w(u'<table class="ajaxEditRelationTable">') |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
630 |
for rentity in related.entities(): |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
631 |
if maydel is None: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
632 |
# Only check permission for the first related. |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
633 |
if self.role == 'subject': |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
634 |
fromeid, toeid = entity.eid, rentity.eid |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
635 |
else: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
636 |
fromeid, toeid = rentity.eid, entity.eid |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
637 |
maydel = self.rdef.has_perm( |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
638 |
req, 'delete', fromeid=fromeid, toeid=toeid) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
639 |
# for each related entity, provide a link to remove the relation |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
640 |
subview = rentity.view(self.item_vid) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
641 |
if maydel: |
10075
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
642 |
if not js_css_added: |
136b5f995f8e
Provide sufficient context to check 'delete' permission in AjaxEditRelationCtxComponent
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
10044
diff
changeset
|
643 |
js_css_added = self.add_js_css() |
10702
f94c812c3669
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
644 |
jscall = text_type(js.ajaxBoxRemoveLinkedEntity( |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
645 |
self.__regid__, entity.eid, rentity.eid, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
646 |
self.fname_remove, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
647 |
self.removed_msg and _(self.removed_msg))) |
6452
6b6a2fa28069
[ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6448
diff
changeset
|
648 |
w(u'<tr><td class="dellink">[<a href="javascript: %s">-</a>]</td>' |
6b6a2fa28069
[ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6448
diff
changeset
|
649 |
'<td class="entity"> %s</td></tr>' % (xml_escape(jscall), |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
650 |
subview)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
651 |
else: |
6452
6b6a2fa28069
[ui] nicer ajax edit relation table (tags box for instance)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6448
diff
changeset
|
652 |
w(u'<tr><td class="entity">%s</td></tr>' % (subview)) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
653 |
w(u'</table>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
654 |
else: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
655 |
w(_('no related entity')) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
656 |
if mayadd: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
657 |
multiple = self.rdef.role_cardinality(self.role) in '*+' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
658 |
w(u'<table><tr><td>') |
10702
f94c812c3669
[py3k] unicode → six.text_type
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
659 |
jscall = text_type(js.ajaxBoxShowSelector( |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
660 |
self.__regid__, entity.eid, self.fname_vocabulary, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
661 |
self.fname_validate, self.added_msg and _(self.added_msg), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
662 |
_(stdmsgs.BUTTON_OK[0]), _(stdmsgs.BUTTON_CANCEL[0]), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
663 |
multiple and self.separator)) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
664 |
w('<a class="button sglink" href="javascript: %s">%s</a>' % ( |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
665 |
xml_escape(jscall), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
666 |
multiple and _('add_relation') or _('update_relation'))) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
667 |
w(u'</td><td>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
668 |
w(u'<div id="%sHolder"></div>' % self.domid) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
669 |
w(u'</td></tr></table>') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
670 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
671 |
|
6461
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
672 |
class RelatedObjectsCtxComponent(EntityCtxComponent): |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
673 |
"""a contextual component to display entities related to another""" |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
674 |
__select__ = EntityCtxComponent.__select__ & partial_has_related_entities() |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
675 |
context = 'navcontentbottom' |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
676 |
rtype = None |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
677 |
role = 'subject' |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
678 |
|
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
679 |
vid = 'list' |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
680 |
|
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
681 |
def render_body(self, w): |
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
682 |
rset = self.entity.related(self.rtype, role(self)) |
6468
40033d536ed8
[ctx component] has no wview method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6461
diff
changeset
|
683 |
self._cw.view(self.vid, rset, w=w) |
6461
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
684 |
|
b546296227ff
[ui component] RelatedObjectsCtxComponent to superseede RelatedObjectsVComponent (still there for bw compat)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6452
diff
changeset
|
685 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
686 |
# old contextual components, deprecated ######################################## |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
687 |
|
10688
fa29f3628a1b
[py3k] use six.add_metaclass
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10666
diff
changeset
|
688 |
@add_metaclass(class_deprecated) |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
689 |
class EntityVComponent(Component): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
690 |
"""abstract base class for additinal components displayed in content |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
691 |
headers and footer according to: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
692 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
693 |
* the displayed entity's type |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
694 |
* a context (currently 'header' or 'footer') |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
695 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
696 |
it should be configured using .accepts, .etype, .rtype, .target and |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
697 |
.context class attributes |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
698 |
""" |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
699 |
__deprecation_warning__ = '[3.10] *VComponent classes are deprecated, use *CtxComponent instead (%(cls)s)' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
700 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
701 |
__registry__ = 'ctxcomponents' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
702 |
__select__ = one_line_rset() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
703 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
704 |
cw_property_defs = { |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
705 |
_('visible'): dict(type='Boolean', default=True, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
706 |
help=_('display the component or not')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
707 |
_('order'): dict(type='Int', default=99, |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
708 |
help=_('display order of the component')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
709 |
_('context'): dict(type='String', default='navtop', |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
710 |
vocabulary=(_('navtop'), _('navbottom'), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
711 |
_('navcontenttop'), _('navcontentbottom'), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
712 |
_('ctxtoolbar')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
713 |
help=_('context where this component should be displayed')), |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
714 |
} |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
715 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
716 |
context = 'navcontentbottom' |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
717 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
718 |
def call(self, view=None): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
719 |
if self.cw_rset is None: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
720 |
self.entity_call(self.cw_extra_kwargs.pop('entity')) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
721 |
else: |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
722 |
self.cell_call(0, 0, view=view) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
723 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
724 |
def cell_call(self, row, col, view=None): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
725 |
self.entity_call(self.cw_rset.get_entity(row, col), view=view) |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
726 |
|
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
727 |
def entity_call(self, entity, view=None): |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
728 |
raise NotImplementedError() |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
729 |
|
10040
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
730 |
class RelatedObjectsVComponent(EntityVComponent): |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
731 |
"""a section to display some related entities""" |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
732 |
__select__ = EntityVComponent.__select__ & partial_has_related_entities() |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
733 |
|
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
734 |
vid = 'list' |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
735 |
# to be defined in concrete classes |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
736 |
rtype = title = None |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
737 |
|
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
738 |
def rql(self): |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
739 |
"""override this method if you want to use a custom rql query""" |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
740 |
return None |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
741 |
|
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
742 |
def cell_call(self, row, col, view=None): |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
743 |
rql = self.rql() |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
744 |
if rql is None: |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
745 |
entity = self.cw_rset.get_entity(row, col) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
746 |
rset = entity.related(self.rtype, role(self)) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
747 |
else: |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
748 |
eid = self.cw_rset[row][col] |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
749 |
rset = self._cw.execute(self.rql(), {'x': eid}) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
750 |
if not rset.rowcount: |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
751 |
return |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
752 |
self.w(u'<div class="%s">' % self.cssclass) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
753 |
self.w(u'<h4>%s</h4>\n' % self._cw._(self.title).capitalize()) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
754 |
self.wview(self.vid, rset) |
2ddeece84808
[web] partial backout of #8391bf718485 to restore RelatedObjectsVComponent
David Douard <david.douard@logilab.fr>
parents:
10006
diff
changeset
|
755 |
self.w(u'</div>') |