author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 26 Aug 2009 10:18:07 +0200 | |
branch | stable |
changeset 3009 | 3deb0fa95761 |
parent 2650 | 18aec79ec3a3 |
child 2920 | 64322aa83a1d |
child 3082 | 99ab33abf414 |
permissions | -rw-r--r-- |
0 | 1 |
""" |
2 |
generic boxes for CubicWeb web client: |
|
3 |
||
4 |
* actions box |
|
5 |
* possible views box |
|
6 |
||
7 |
additional (disabled by default) boxes |
|
8 |
* schema box |
|
9 |
* startup views box |
|
10 |
||
11 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1876
diff
changeset
|
12 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 13 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1876
diff
changeset
|
14 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 15 |
""" |
16 |
__docformat__ = "restructuredtext en" |
|
1876 | 17 |
_ = unicode |
0 | 18 |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
19 |
from logilab.mtconverter import xml_escape |
0 | 20 |
|
1132 | 21 |
from cubicweb.selectors import match_user_groups, non_final_entity |
2265
4c028cb136a4
add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
22 |
from cubicweb.view import EntityView |
4c028cb136a4
add import to remove deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
23 |
from cubicweb.schema import display_name |
0 | 24 |
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem |
1285
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
25 |
from cubicweb.web import uicfg |
663 | 26 |
from cubicweb.web.box import BoxTemplate |
0 | 27 |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
28 |
|
0 | 29 |
class EditBox(BoxTemplate): |
30 |
""" |
|
31 |
box with all actions impacting the entity displayed: edit, copy, delete |
|
32 |
change state, add related entities |
|
33 |
""" |
|
34 |
id = 'edit_box' |
|
809 | 35 |
__select__ = BoxTemplate.__select__ & non_final_entity() |
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
36 |
|
0 | 37 |
title = _('actions') |
38 |
order = 2 |
|
1285
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
39 |
# class attributes below are actually stored in the uicfg module since we |
d5ce82d65c2b
for a correct handling of rtags, they should not ever be reloaded and they should be initialized once registration is finished
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
40 |
# don't want them to be reloaded |
1739 | 41 |
appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
42 |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
43 |
def call(self, view=None, **kwargs): |
0 | 44 |
_ = self.req._ |
45 |
title = _(self.title) |
|
46 |
if self.rset: |
|
47 |
etypes = self.rset.column_types(0) |
|
48 |
if len(etypes) == 1: |
|
49 |
plural = self.rset.rowcount > 1 and 'plural' or '' |
|
50 |
etypelabel = display_name(self.req, iter(etypes).next(), plural) |
|
51 |
title = u'%s - %s' % (title, etypelabel.lower()) |
|
52 |
box = BoxWidget(title, self.id, _class="greyBoxFrame") |
|
53 |
# build list of actions |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2443
diff
changeset
|
54 |
actions = self.vreg['actions'].possible_actions(self.req, self.rset, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2443
diff
changeset
|
55 |
view=view) |
0 | 56 |
add_menu = BoxMenu(_('add')) # 'addrelated' category |
57 |
other_menu = BoxMenu(_('more actions')) # 'moreactions' category |
|
58 |
searchstate = self.req.search_state[0] |
|
59 |
for category, menu in (('mainactions', box), |
|
60 |
('addrelated', add_menu), |
|
61 |
('moreactions', other_menu)): |
|
62 |
for action in actions.get(category, ()): |
|
63 |
menu.append(self.box_action(action)) |
|
64 |
if self.rset and self.rset.rowcount == 1 and \ |
|
65 |
not self.schema[self.rset.description[0][0]].is_final() and \ |
|
66 |
searchstate == 'normal': |
|
67 |
entity = self.rset.get_entity(0, 0) |
|
68 |
#entity.complete() |
|
69 |
if add_menu.items: |
|
70 |
self.info('explicit actions defined, ignoring potential rtags for %s', |
|
71 |
entity.e_schema) |
|
72 |
else: |
|
73 |
# some addrelated actions may be specified but no one is selectable |
|
74 |
# in which case we should not fallback to schema_actions. The proper |
|
75 |
# way to avoid this is to override add_related_schemas() on the |
|
76 |
# entity class to return an empty list |
|
77 |
for action in self.schema_actions(entity): |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
78 |
add_menu.append(action) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
79 |
self.workflow_actions(entity, box) |
0 | 80 |
if box.is_empty() and not other_menu.is_empty(): |
81 |
box.items = other_menu.items |
|
82 |
other_menu.items = [] |
|
83 |
self.add_submenu(box, add_menu, _('add')) |
|
84 |
self.add_submenu(box, other_menu) |
|
85 |
if not box.is_empty(): |
|
86 |
box.render(self.w) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
87 |
|
0 | 88 |
def add_submenu(self, box, submenu, label_prefix=None): |
89 |
if len(submenu.items) == 1: |
|
90 |
boxlink = submenu.items[0] |
|
91 |
if label_prefix: |
|
92 |
boxlink.label = u'%s %s' % (label_prefix, boxlink.label) |
|
93 |
box.append(boxlink) |
|
94 |
elif submenu.items: |
|
95 |
box.append(submenu) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
96 |
|
0 | 97 |
def schema_actions(self, entity): |
98 |
user = self.req.user |
|
99 |
actions = [] |
|
100 |
_ = self.req._ |
|
101 |
eschema = entity.e_schema |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
102 |
for rschema, teschema, x in self.add_related_schemas(entity): |
0 | 103 |
if x == 'subject': |
1848
981b8dc9e4d0
fix i18n msgstr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1752
diff
changeset
|
104 |
label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
0 | 105 |
url = self.linkto_url(entity, rschema, teschema, 'object') |
106 |
else: |
|
1848
981b8dc9e4d0
fix i18n msgstr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1752
diff
changeset
|
107 |
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
0 | 108 |
url = self.linkto_url(entity, rschema, teschema, 'subject') |
109 |
actions.append(self.mk_action(_(label), url)) |
|
110 |
return actions |
|
111 |
||
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
112 |
def add_related_schemas(self, entity): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
113 |
"""this is actually used ui method to generate 'addrelated' actions from |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
114 |
the schema. |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
115 |
|
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
116 |
If you're using explicit 'addrelated' actions for an entity types, you |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
117 |
should probably overrides this method to return an empty list else you |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
118 |
may get some unexpected actions. |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
119 |
""" |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
120 |
req = self.req |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
121 |
eschema = entity.e_schema |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
122 |
for role, rschemas in (('subject', eschema.subject_relations()), |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
123 |
('object', eschema.object_relations())): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
124 |
for rschema in rschemas: |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
125 |
if rschema.is_final(): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
126 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
127 |
# check the relation can be added as well |
1739 | 128 |
# XXX consider autoform_permissions_overrides? |
129 |
if role == 'subject'and not rschema.has_perm(req, 'add', |
|
130 |
fromeid=entity.eid): |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
131 |
continue |
1739 | 132 |
if role == 'object'and not rschema.has_perm(req, 'add', |
133 |
toeid=entity.eid): |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
134 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
135 |
# check the target types can be added as well |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
136 |
for teschema in rschema.targets(eschema, role): |
1739 | 137 |
if not self.appearsin_addmenu.etype_get(eschema, rschema, |
138 |
role, teschema): |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
139 |
continue |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
140 |
if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
141 |
yield rschema, teschema, role |
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
142 |
|
0 | 143 |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
144 |
def workflow_actions(self, entity, box): |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
145 |
if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
399 | 146 |
_ = self.req._ |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
147 |
state = entity.in_state[0] |
2443
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
148 |
menu_title = u'%s: %s' % (_('state'), state.view('text')) |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
149 |
menu_items = [] |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
150 |
for tr in state.transitions(entity): |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
151 |
url = entity.absolute_url(vid='statuschange', treid=tr.eid) |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
152 |
menu_items.append(self.mk_action(_(tr.name), url)) |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
153 |
wfurl = self.build_url('cwetype/%s'%entity.e_schema, vid='workflow') |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
154 |
menu_items.append(self.mk_action(_('view workflow'), wfurl)) |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
155 |
wfurl = entity.absolute_url(vid='wfhistory') |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
156 |
menu_items.append(self.mk_action(_('view history'), wfurl)) |
b36f759bd2cc
#343093: display workflow
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2312
diff
changeset
|
157 |
box.append(BoxMenu(menu_title, menu_items)) |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
158 |
return None |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
159 |
|
0 | 160 |
def linkto_url(self, entity, rtype, etype, target): |
161 |
return self.build_url(vid='creation', etype=etype, |
|
162 |
__linkto='%s:%s:%s' % (rtype, entity.eid, target), |
|
163 |
__redirectpath=entity.rest_path(), # should not be url quoted! |
|
164 |
__redirectvid=self.req.form.get('vid', '')) |
|
165 |
||
166 |
||
167 |
class SearchBox(BoxTemplate): |
|
168 |
"""display a box with a simple search form""" |
|
169 |
id = 'search_box' |
|
809 | 170 |
|
0 | 171 |
visible = True # enabled by default |
172 |
title = _('search') |
|
173 |
order = 0 |
|
174 |
formdef = u"""<form action="%s"> |
|
175 |
<table id="tsearch"><tr><td> |
|
176 |
<input id="norql" type="text" accesskey="q" tabindex="%s" title="search text" value="%s" name="rql" /> |
|
177 |
<input type="hidden" name="__fromsearchbox" value="1" /> |
|
178 |
<input type="hidden" name="subvid" value="tsearch" /> |
|
179 |
</td><td> |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
536
diff
changeset
|
180 |
<input tabindex="%s" type="submit" id="rqlboxsubmit" class="rqlsubmit" value="" /> |
0 | 181 |
</td></tr></table> |
182 |
</form>""" |
|
183 |
||
184 |
def call(self, view=None, **kwargs): |
|
185 |
req = self.req |
|
186 |
if req.form.pop('__fromsearchbox', None): |
|
187 |
rql = req.form.get('rql', '') |
|
188 |
else: |
|
189 |
rql = '' |
|
190 |
form = self.formdef % (req.build_url('view'), req.next_tabindex(), |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2265
diff
changeset
|
191 |
xml_escape(rql), req.next_tabindex()) |
0 | 192 |
title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title) |
193 |
box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False) |
|
194 |
box.append(BoxHtml(form)) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
195 |
box.render(self.w) |
0 | 196 |
|
197 |
||
198 |
# boxes disabled by default ################################################### |
|
199 |
||
200 |
class PossibleViewsBox(BoxTemplate): |
|
201 |
"""display a box containing links to all possible views""" |
|
202 |
id = 'possible_views_box' |
|
809 | 203 |
__select__ = BoxTemplate.__select__ & match_user_groups('users', 'managers') |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
204 |
|
809 | 205 |
visible = False |
0 | 206 |
title = _('possible views') |
207 |
order = 10 |
|
208 |
||
209 |
def call(self, **kwargs): |
|
210 |
box = BoxWidget(self.req._(self.title), self.id) |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2443
diff
changeset
|
211 |
views = [v for v in self.vreg['views'].possible_views(self.req, |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2443
diff
changeset
|
212 |
rset=self.rset) |
613 | 213 |
if v.category != 'startupview'] |
214 |
for category, views in self.sort_actions(views): |
|
0 | 215 |
menu = BoxMenu(category) |
613 | 216 |
for view in views: |
217 |
menu.append(self.box_action(view)) |
|
0 | 218 |
box.append(menu) |
219 |
if not box.is_empty(): |
|
220 |
box.render(self.w) |
|
221 |
||
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
107
diff
changeset
|
222 |
|
0 | 223 |
class StartupViewsBox(BoxTemplate): |
224 |
"""display a box containing links to all startup views""" |
|
225 |
id = 'startup_views_box' |
|
226 |
visible = False # disabled by default |
|
227 |
title = _('startup views') |
|
228 |
order = 70 |
|
229 |
||
230 |
def call(self, **kwargs): |
|
231 |
box = BoxWidget(self.req._(self.title), self.id) |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2443
diff
changeset
|
232 |
for view in self.vreg['views'].possible_views(self.req, None): |
0 | 233 |
if view.category == 'startupview': |
234 |
box.append(self.box_action(view)) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
235 |
|
0 | 236 |
if not box.is_empty(): |
237 |
box.render(self.w) |
|
238 |
||
1263 | 239 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
240 |
# helper classes ############################################################## |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
241 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
242 |
class SideBoxView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
243 |
"""helper view class to display some entities in a sidebox""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
244 |
id = 'sidebox' |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
245 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
246 |
def call(self, boxclass='sideBox', title=u''): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
247 |
"""display a list of entities by calling their <item_vid> view""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
248 |
if title: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
249 |
self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % title) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
250 |
self.w(u'<div class="%s"><div class="sideBoxBody">' % boxclass) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
251 |
# if not too much entities, show them all in a list |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
252 |
maxrelated = self.req.property_value('navigation.related-limit') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
253 |
if self.rset.rowcount <= maxrelated: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
254 |
if len(self.rset) == 1: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
255 |
self.wview('incontext', self.rset, row=0) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
256 |
elif 1 < len(self.rset) < 5: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
257 |
self.wview('csv', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
258 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
259 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
260 |
# else show links to display related entities |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
261 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
262 |
self.rset.limit(maxrelated) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
263 |
rql = self.rset.printable_rql(encoded=False) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
264 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
265 |
self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
266 |
self.req._('see them all'))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
267 |
self.w(u'</div>\n</div>\n') |