author | Laurent Peuch <cortex@worlddomination.be> |
Fri, 27 Sep 2019 06:51:29 +0200 | |
changeset 12772 | a2b8c201727f |
parent 12567 | 26744ad37953 |
permissions | -rw-r--r-- |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
1 |
# copyright 2003-2012 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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
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:
4490
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5949
2a273c896a38
[box] provide a new generic base box class to edit relation to simple entities, backported from the 'tag' cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5927
diff
changeset
|
18 |
"""abstract box classes for CubicWeb web client""" |
0 | 19 |
|
11767
432f87a63057
flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11057
diff
changeset
|
20 |
|
10666
7f6b5f023884
[py3k] replace '_ = unicode' in global scope (closes #7589459)
Rémi Cardona <remi.cardona@logilab.fr>
parents:
8900
diff
changeset
|
21 |
from cubicweb import _ |
0 | 22 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2159
diff
changeset
|
23 |
from logilab.mtconverter import xml_escape |
12503
b01dd0ef43aa
Drop most deprecated code in cubicweb.web
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12502
diff
changeset
|
24 |
from logilab.common.deprecation import class_deprecated |
0 | 25 |
|
6490
34359fbde6ef
[components] add missing imports for code copied/pasted. Forgot to run pylint afterward...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6141
diff
changeset
|
26 |
from cubicweb import Unauthorized, role as get_role |
2710
40789c3044f3
[web.box] remove deprecation warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2381
diff
changeset
|
27 |
from cubicweb.schema import display_name |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
28 |
from cubicweb.predicates import no_cnx, 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
|
29 |
from cubicweb.view import View |
0 | 30 |
from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget, |
12502
e651d5f24cb5
[web] use Separator "component" instead of deprecated BoxSeparator widget
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12501
diff
changeset
|
31 |
RawBoxItem) |
0 | 32 |
from cubicweb.web.action import UnregisteredAction |
12502
e651d5f24cb5
[web] use Separator "component" instead of deprecated BoxSeparator widget
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12501
diff
changeset
|
33 |
from cubicweb.web.component import ( |
e651d5f24cb5
[web] use Separator "component" instead of deprecated BoxSeparator widget
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12501
diff
changeset
|
34 |
EditRelationMixIn, |
e651d5f24cb5
[web] use Separator "component" instead of deprecated BoxSeparator widget
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12501
diff
changeset
|
35 |
Separator, |
e651d5f24cb5
[web] use Separator "component" instead of deprecated BoxSeparator widget
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12501
diff
changeset
|
36 |
) |
0 | 37 |
|
38 |
||
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
39 |
def sort_by_category(actions, categories_in_order=None): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
40 |
"""return a list of (category, actions_sorted_by_title)""" |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
41 |
result = [] |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
42 |
actions_by_cat = {} |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
43 |
for action in actions: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
44 |
actions_by_cat.setdefault(action.category, []).append( |
12501
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
45 |
(action.title, action)) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
46 |
for key, values in actions_by_cat.items(): |
10715
edd1ba9bb030
[py3k] Don't sort Action objects
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10688
diff
changeset
|
47 |
actions_by_cat[key] = [act for title, act in sorted(values, key=lambda x: x[0])] |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
48 |
if categories_in_order: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
49 |
for cat in categories_in_order: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
50 |
if cat in actions_by_cat: |
12501
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
51 |
result.append((cat, actions_by_cat[cat])) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
52 |
for item in sorted(actions_by_cat.items()): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
53 |
result.append(item) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
54 |
return result |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
55 |
|
1493 | 56 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
57 |
# old box system, deprecated ################################################### |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
58 |
|
12567
26744ad37953
Drop python2 support
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12503
diff
changeset
|
59 |
class BoxTemplate(View, metaclass=class_deprecated): |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
60 |
"""base template for boxes, usually a (contextual) list of possible |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
61 |
actions. Various classes attributes may be used to control the box |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
62 |
rendering. |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
63 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
64 |
You may override one of the formatting callbacks if this is not necessary |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
65 |
for your custom box. |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
66 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
67 |
Classes inheriting from this class usually only have to override call |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
68 |
to fetch desired actions, and then to do something like :: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
69 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
70 |
box.render(self.w) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
71 |
""" |
12501
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
72 |
__deprecation_warning__ = ( |
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
73 |
'[3.10] *BoxTemplate classes are deprecated, use *CtxComponent instead (%(cls)s)' |
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
74 |
) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
75 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
76 |
__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
|
77 |
__select__ = ~no_cnx() |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
78 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
79 |
categories_in_order = () |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
80 |
cw_property_defs = { |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
81 |
_('visible'): dict(type='Boolean', default=True, |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
82 |
help=_('display the box or not')), |
12501
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
83 |
_('order'): dict(type='Int', default=99, |
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
84 |
help=_('display order of the box')), |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
85 |
# XXX 'incontext' boxes are handled by the default primary view |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
86 |
_('context'): dict(type='String', default='left', |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
87 |
vocabulary=(_('left'), _('incontext'), _('right')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
88 |
help=_('context where this box should be displayed')), |
12501
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
89 |
} |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
90 |
context = 'left' |
0 | 91 |
|
92 |
def sort_actions(self, actions): |
|
93 |
"""return a list of (category, actions_sorted_by_title)""" |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
94 |
return sort_by_category(actions, self.categories_in_order) |
0 | 95 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
96 |
def mk_action(self, title, url, escape=True, **kwargs): |
0 | 97 |
"""factory function to create dummy actions compatible with the |
98 |
.format_actions method |
|
99 |
""" |
|
100 |
if escape: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2159
diff
changeset
|
101 |
title = xml_escape(title) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
102 |
return self.box_action(self._action(title, url, **kwargs)) |
1493 | 103 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
104 |
def _action(self, title, url, **kwargs): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
105 |
return UnregisteredAction(self._cw, title, url, **kwargs) |
0 | 106 |
|
107 |
# formating callbacks |
|
108 |
||
109 |
def boxitem_link_tooltip(self, action): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
110 |
if action.__regid__: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
111 |
return u'keyword: %s' % action.__regid__ |
0 | 112 |
return u'' |
113 |
||
114 |
def box_action(self, action): |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
115 |
klass = getattr(action, 'html_class', lambda: None)() |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
116 |
return BoxLink(action.url(), self._cw._(action.title), |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
117 |
klass, self.boxitem_link_tooltip(action)) |
1493 | 118 |
|
0 | 119 |
|
120 |
class RQLBoxTemplate(BoxTemplate): |
|
121 |
"""abstract box for boxes displaying the content of a rql query not |
|
122 |
related to the current result set. |
|
123 |
""" |
|
124 |
||
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:
6499
diff
changeset
|
125 |
# 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:
6499
diff
changeset
|
126 |
rql = title = None |
1493 | 127 |
|
0 | 128 |
def to_display_rql(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
129 |
assert self.rql is not None, self.__regid__ |
0 | 130 |
return (self.rql,) |
1493 | 131 |
|
0 | 132 |
def call(self, **kwargs): |
133 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
134 |
rset = self._cw.execute(*self.to_display_rql()) |
0 | 135 |
except Unauthorized: |
136 |
# can't access to something in the query, forget this box |
|
137 |
return |
|
138 |
if len(rset) == 0: |
|
139 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
140 |
box = BoxWidget(self._cw._(self.title), self.__regid__) |
0 | 141 |
for i, (teid, tname) in enumerate(rset): |
142 |
entity = rset.get_entity(i, 0) |
|
143 |
box.append(self.mk_action(tname, entity.absolute_url())) |
|
144 |
box.render(w=self.w) |
|
145 |
||
1493 | 146 |
|
0 | 147 |
class UserRQLBoxTemplate(RQLBoxTemplate): |
148 |
"""same as rql box template but the rql is build using the eid of the |
|
149 |
request's user |
|
150 |
""" |
|
151 |
||
152 |
def to_display_rql(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
153 |
assert self.rql is not None, self.__regid__ |
5979
561b6c2eb288
[web] eid key is deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
5952
diff
changeset
|
154 |
return (self.rql, {'x': self._cw.user.eid}) |
1493 | 155 |
|
0 | 156 |
|
157 |
class EntityBoxTemplate(BoxTemplate): |
|
158 |
"""base class for boxes related to a single entity""" |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
159 |
__select__ = BoxTemplate.__select__ & one_line_rset() |
0 | 160 |
context = 'incontext' |
1493 | 161 |
|
0 | 162 |
def call(self, row=0, col=0, **kwargs): |
526 | 163 |
"""classes inheriting from EntityBoxTemplate should define cell_call""" |
0 | 164 |
self.cell_call(row, col, **kwargs) |
165 |
||
166 |
||
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
167 |
class EditRelationBoxTemplate(EditRelationMixIn, EntityBoxTemplate): |
0 | 168 |
"""base class for boxes which let add or remove entities linked |
169 |
by a given relation |
|
170 |
||
171 |
subclasses should define at least id, rtype and target |
|
172 |
class attributes. |
|
173 |
""" |
|
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:
6499
diff
changeset
|
174 |
rtype = None |
12501
4548234cccf9
Flake8 cubicweb/web/box.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
175 |
|
1624
baf484a182cd
should take arbitrary arguments
sylvain.thenault@logilab.fr
parents:
1493
diff
changeset
|
176 |
def cell_call(self, row, col, view=None, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
177 |
self._cw.add_js('cubicweb.ajax.js') |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
178 |
entity = self.cw_rset.get_entity(row, col) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
179 |
title = display_name(self._cw, self.rtype, get_role(self), |
8900
010a59e12d89
use cw_etype instead of __regid__
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8190
diff
changeset
|
180 |
context=entity.cw_etype) |
6017
5f6a60ea8544
[relations in ui] provide context information when computing label for a relation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5979
diff
changeset
|
181 |
box = SideBoxWidget(title, self.__regid__) |
2757
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
182 |
related = self.related_boxitems(entity) |
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
183 |
unrelated = self.unrelated_boxitems(entity) |
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
184 |
box.extend(related) |
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
185 |
if related and unrelated: |
12502
e651d5f24cb5
[web] use Separator "component" instead of deprecated BoxSeparator widget
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12501
diff
changeset
|
186 |
box.append(Separator()) |
2757
c8e28e1754f0
B [web.box] fix EditRelationBoxTemplate in case neither related nor unrelated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2710
diff
changeset
|
187 |
box.extend(unrelated) |
0 | 188 |
box.render(self.w) |
189 |
||
190 |
def box_item(self, entity, etarget, rql, label): |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
191 |
label = super(EditRelationBoxTemplate, self).box_item( |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
192 |
entity, etarget, rql, label) |
0 | 193 |
return RawBoxItem(label, liclass=u'invisible') |