author | David Douard <david.douard@logilab.fr> |
Thu, 13 Jun 2013 17:32:49 +0200 | |
changeset 9009 | 195e519fe97c |
parent 8900 | 010a59e12d89 |
child 10666 | 7f6b5f023884 |
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 |
|
20 |
__docformat__ = "restructuredtext en" |
|
2159 | 21 |
_ = unicode |
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 |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
24 |
from logilab.common.deprecation import class_deprecated, class_renamed |
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 |
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
|
30 |
from cubicweb.web import INTERNAL_FIELD_VALUE, stdmsgs |
0 | 31 |
from cubicweb.web.htmlwidgets import (BoxLink, BoxWidget, SideBoxWidget, |
250
7fd7a0d387d7
new RelatedEntityBoxTemplate base class
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
237
diff
changeset
|
32 |
RawBoxItem, BoxSeparator) |
0 | 33 |
from cubicweb.web.action import UnregisteredAction |
34 |
||
35 |
||
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
36 |
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
|
37 |
"""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
|
38 |
result = [] |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
39 |
actions_by_cat = {} |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
40 |
for action in actions: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
41 |
actions_by_cat.setdefault(action.category, []).append( |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
42 |
(action.title, action) ) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
43 |
for key, values in actions_by_cat.items(): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
44 |
actions_by_cat[key] = [act for title, act in sorted(values)] |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
45 |
if categories_in_order: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
46 |
for cat in categories_in_order: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
47 |
if cat in actions_by_cat: |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
48 |
result.append( (cat, actions_by_cat[cat]) ) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
49 |
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
|
50 |
result.append(item) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
51 |
return result |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
52 |
|
1493 | 53 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
54 |
# old box system, deprecated ################################################### |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
55 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
56 |
class BoxTemplate(View): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
57 |
"""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
|
58 |
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
|
59 |
rendering. |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
60 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
61 |
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
|
62 |
for your custom box. |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
63 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
67 |
box.render(self.w) |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
68 |
""" |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
69 |
__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
|
70 |
__deprecation_warning__ = '[3.10] *BoxTemplate classes are deprecated, use *CtxComponent instead (%(cls)s)' |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
71 |
|
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
72 |
__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
|
73 |
__select__ = ~no_cnx() |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
74 |
|
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
75 |
categories_in_order = () |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
76 |
cw_property_defs = { |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
77 |
_('visible'): dict(type='Boolean', default=True, |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
78 |
help=_('display the box or not')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
79 |
_('order'): dict(type='Int', default=99, |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
80 |
help=_('display order of the box')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
81 |
# 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
|
82 |
_('context'): dict(type='String', default='left', |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
83 |
vocabulary=(_('left'), _('incontext'), _('right')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
84 |
help=_('context where this box should be displayed')), |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
85 |
} |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
86 |
context = 'left' |
0 | 87 |
|
88 |
def sort_actions(self, actions): |
|
89 |
"""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
|
90 |
return sort_by_category(actions, self.categories_in_order) |
0 | 91 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
92 |
def mk_action(self, title, url, escape=True, **kwargs): |
0 | 93 |
"""factory function to create dummy actions compatible with the |
94 |
.format_actions method |
|
95 |
""" |
|
96 |
if escape: |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2159
diff
changeset
|
97 |
title = xml_escape(title) |
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
98 |
return self.box_action(self._action(title, url, **kwargs)) |
1493 | 99 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
100 |
def _action(self, title, url, **kwargs): |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
101 |
return UnregisteredAction(self._cw, title, url, **kwargs) |
0 | 102 |
|
103 |
# formating callbacks |
|
104 |
||
105 |
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
|
106 |
if action.__regid__: |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
107 |
return u'keyword: %s' % action.__regid__ |
0 | 108 |
return u'' |
109 |
||
110 |
def box_action(self, action): |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
klass, self.boxitem_link_tooltip(action)) |
1493 | 114 |
|
0 | 115 |
|
116 |
class RQLBoxTemplate(BoxTemplate): |
|
117 |
"""abstract box for boxes displaying the content of a rql query not |
|
118 |
related to the current result set. |
|
119 |
""" |
|
120 |
||
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
|
121 |
# 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
|
122 |
rql = title = None |
1493 | 123 |
|
0 | 124 |
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
|
125 |
assert self.rql is not None, self.__regid__ |
0 | 126 |
return (self.rql,) |
1493 | 127 |
|
0 | 128 |
def call(self, **kwargs): |
129 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
130 |
rset = self._cw.execute(*self.to_display_rql()) |
0 | 131 |
except Unauthorized: |
132 |
# can't access to something in the query, forget this box |
|
133 |
return |
|
134 |
if len(rset) == 0: |
|
135 |
return |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3230
diff
changeset
|
136 |
box = BoxWidget(self._cw._(self.title), self.__regid__) |
0 | 137 |
for i, (teid, tname) in enumerate(rset): |
138 |
entity = rset.get_entity(i, 0) |
|
139 |
box.append(self.mk_action(tname, entity.absolute_url())) |
|
140 |
box.render(w=self.w) |
|
141 |
||
1493 | 142 |
|
0 | 143 |
class UserRQLBoxTemplate(RQLBoxTemplate): |
144 |
"""same as rql box template but the rql is build using the eid of the |
|
145 |
request's user |
|
146 |
""" |
|
147 |
||
148 |
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
|
149 |
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
|
150 |
return (self.rql, {'x': self._cw.user.eid}) |
1493 | 151 |
|
0 | 152 |
|
153 |
class EntityBoxTemplate(BoxTemplate): |
|
154 |
"""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
|
155 |
__select__ = BoxTemplate.__select__ & one_line_rset() |
0 | 156 |
context = 'incontext' |
1493 | 157 |
|
0 | 158 |
def call(self, row=0, col=0, **kwargs): |
526 | 159 |
"""classes inheriting from EntityBoxTemplate should define cell_call""" |
0 | 160 |
self.cell_call(row, col, **kwargs) |
161 |
||
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
162 |
from cubicweb.web.component import AjaxEditRelationCtxComponent, EditRelationMixIn |
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
163 |
|
0 | 164 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
165 |
class EditRelationBoxTemplate(EditRelationMixIn, EntityBoxTemplate): |
0 | 166 |
"""base class for boxes which let add or remove entities linked |
167 |
by a given relation |
|
168 |
||
169 |
subclasses should define at least id, rtype and target |
|
170 |
class attributes. |
|
171 |
""" |
|
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
|
172 |
rtype = None |
1624
baf484a182cd
should take arbitrary arguments
sylvain.thenault@logilab.fr
parents:
1493
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
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
|
182 |
if related and unrelated: |
0 | 183 |
box.append(BoxSeparator()) |
2757
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(unrelated) |
0 | 185 |
box.render(self.w) |
186 |
||
187 |
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
|
188 |
label = super(EditRelationBoxTemplate, self).box_item( |
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
189 |
entity, etarget, rql, label) |
0 | 190 |
return RawBoxItem(label, liclass=u'invisible') |
1493 | 191 |
|
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
|
192 |
|
6140
65a619eb31c4
[boxes] introduce new boxes system
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6017
diff
changeset
|
193 |
AjaxEditRelationBoxTemplate = class_renamed( |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6140
diff
changeset
|
194 |
'AjaxEditRelationBoxTemplate', AjaxEditRelationCtxComponent, |
6499
c4123c741c66
[deprecation] enhanced messages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6490
diff
changeset
|
195 |
'[3.10] AjaxEditRelationBoxTemplate has been renamed to AjaxEditRelationCtxComponent (%(cls)s)') |
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
|
196 |