author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 19 May 2009 13:21:29 +0200 | |
branch | stable |
changeset 1867 | b2fe73a55899 |
parent 1848 | 981b8dc9e4d0 |
child 1876 | b06a797448aa |
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 |
|
612 | 12 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 13 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
14 |
""" |
|
15 |
__docformat__ = "restructuredtext en" |
|
16 |
||
17 |
from logilab.mtconverter import html_escape |
|
18 |
||
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
|
19 |
from cubicweb.rtags import RelationTags |
1132 | 20 |
from cubicweb.selectors import match_user_groups, non_final_entity |
0 | 21 |
from cubicweb.web.htmlwidgets import BoxWidget, BoxMenu, BoxHtml, RawBoxItem |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
22 |
from cubicweb.view import EntityView |
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
|
23 |
from cubicweb.web import uicfg |
663 | 24 |
from cubicweb.web.box import BoxTemplate |
0 | 25 |
|
26 |
_ = unicode |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
27 |
|
0 | 28 |
class EditBox(BoxTemplate): |
29 |
""" |
|
30 |
box with all actions impacting the entity displayed: edit, copy, delete |
|
31 |
change state, add related entities |
|
32 |
""" |
|
33 |
id = 'edit_box' |
|
809 | 34 |
__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
|
35 |
|
0 | 36 |
title = _('actions') |
37 |
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
|
38 |
# 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
|
39 |
# don't want them to be reloaded |
1739 | 40 |
appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
41 |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
42 |
def call(self, view=None, **kwargs): |
0 | 43 |
_ = self.req._ |
44 |
title = _(self.title) |
|
45 |
if self.rset: |
|
46 |
etypes = self.rset.column_types(0) |
|
47 |
if len(etypes) == 1: |
|
48 |
plural = self.rset.rowcount > 1 and 'plural' or '' |
|
49 |
etypelabel = display_name(self.req, iter(etypes).next(), plural) |
|
50 |
title = u'%s - %s' % (title, etypelabel.lower()) |
|
51 |
box = BoxWidget(title, self.id, _class="greyBoxFrame") |
|
52 |
# build list of actions |
|
1247
3332c92d950c
give view when selecting actions
sylvain.thenault@logilab.fr
parents:
1242
diff
changeset
|
53 |
actions = self.vreg.possible_actions(self.req, self.rset, view=view) |
0 | 54 |
add_menu = BoxMenu(_('add')) # 'addrelated' category |
55 |
other_menu = BoxMenu(_('more actions')) # 'moreactions' category |
|
56 |
searchstate = self.req.search_state[0] |
|
57 |
for category, menu in (('mainactions', box), |
|
58 |
('addrelated', add_menu), |
|
59 |
('moreactions', other_menu)): |
|
60 |
for action in actions.get(category, ()): |
|
61 |
menu.append(self.box_action(action)) |
|
62 |
if self.rset and self.rset.rowcount == 1 and \ |
|
63 |
not self.schema[self.rset.description[0][0]].is_final() and \ |
|
64 |
searchstate == 'normal': |
|
65 |
entity = self.rset.get_entity(0, 0) |
|
66 |
#entity.complete() |
|
67 |
if add_menu.items: |
|
68 |
self.info('explicit actions defined, ignoring potential rtags for %s', |
|
69 |
entity.e_schema) |
|
70 |
else: |
|
71 |
# some addrelated actions may be specified but no one is selectable |
|
72 |
# in which case we should not fallback to schema_actions. The proper |
|
73 |
# way to avoid this is to override add_related_schemas() on the |
|
74 |
# entity class to return an empty list |
|
75 |
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
|
76 |
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
|
77 |
self.workflow_actions(entity, box) |
0 | 78 |
if box.is_empty() and not other_menu.is_empty(): |
79 |
box.items = other_menu.items |
|
80 |
other_menu.items = [] |
|
81 |
self.add_submenu(box, add_menu, _('add')) |
|
82 |
self.add_submenu(box, other_menu) |
|
83 |
if not box.is_empty(): |
|
84 |
box.render(self.w) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
85 |
|
0 | 86 |
def add_submenu(self, box, submenu, label_prefix=None): |
87 |
if len(submenu.items) == 1: |
|
88 |
boxlink = submenu.items[0] |
|
89 |
if label_prefix: |
|
90 |
boxlink.label = u'%s %s' % (label_prefix, boxlink.label) |
|
91 |
box.append(boxlink) |
|
92 |
elif submenu.items: |
|
93 |
box.append(submenu) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
94 |
|
0 | 95 |
def schema_actions(self, entity): |
96 |
user = self.req.user |
|
97 |
actions = [] |
|
98 |
_ = self.req._ |
|
99 |
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
|
100 |
for rschema, teschema, x in self.add_related_schemas(entity): |
0 | 101 |
if x == 'subject': |
1848
981b8dc9e4d0
fix i18n msgstr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1752
diff
changeset
|
102 |
label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
0 | 103 |
url = self.linkto_url(entity, rschema, teschema, 'object') |
104 |
else: |
|
1848
981b8dc9e4d0
fix i18n msgstr
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1752
diff
changeset
|
105 |
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
0 | 106 |
url = self.linkto_url(entity, rschema, teschema, 'subject') |
107 |
actions.append(self.mk_action(_(label), url)) |
|
108 |
return actions |
|
109 |
||
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
|
110 |
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
|
111 |
"""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
|
112 |
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
|
113 |
|
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 |
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
|
115 |
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
|
116 |
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
|
117 |
""" |
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 |
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
|
119 |
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
|
120 |
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
|
121 |
('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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
# check the relation can be added as well |
1739 | 126 |
# XXX consider autoform_permissions_overrides? |
127 |
if role == 'subject'and not rschema.has_perm(req, 'add', |
|
128 |
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
|
129 |
continue |
1739 | 130 |
if role == 'object'and not rschema.has_perm(req, 'add', |
131 |
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
|
132 |
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
|
133 |
# 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
|
134 |
for teschema in rschema.targets(eschema, role): |
1739 | 135 |
if not self.appearsin_addmenu.etype_get(eschema, rschema, |
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
|
0 | 141 |
|
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
142 |
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
|
143 |
if 'in_state' in entity.e_schema.subject_relations() and entity.in_state: |
399 | 144 |
_ = self.req._ |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
145 |
state = entity.in_state[0] |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
146 |
transitions = list(state.transitions(entity)) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
147 |
if transitions: |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
148 |
menu_title = u'%s: %s' % (_('state'), state.view('text')) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
149 |
menu_items = [] |
1113
5608c79c789b
[boxes] that looked like a redundant call (needs review)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
859
diff
changeset
|
150 |
for tr in transitions: |
185
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
151 |
url = entity.absolute_url(vid='statuschange', treid=tr.eid) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
152 |
menu_items.append(self.mk_action(_(tr.name), url)) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
153 |
box.append(BoxMenu(menu_title, menu_items)) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
154 |
# when there are no possible transition, put state if the menu if |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
155 |
# there are some other actions |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
156 |
elif not box.is_empty(): |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
157 |
menu_title = u'<a title="%s">%s: <i>%s</i></a>' % ( |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
158 |
_('no possible transition'), _('state'), state.view('text')) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
159 |
box.append(RawBoxItem(menu_title, 'boxMainactions')) |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
160 |
return None |
9fc69c46e5e7
EditBox: extract workflow actions construction in a separate method
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
143
diff
changeset
|
161 |
|
0 | 162 |
def linkto_url(self, entity, rtype, etype, target): |
163 |
return self.build_url(vid='creation', etype=etype, |
|
164 |
__linkto='%s:%s:%s' % (rtype, entity.eid, target), |
|
165 |
__redirectpath=entity.rest_path(), # should not be url quoted! |
|
166 |
__redirectvid=self.req.form.get('vid', '')) |
|
167 |
||
168 |
||
169 |
class SearchBox(BoxTemplate): |
|
170 |
"""display a box with a simple search form""" |
|
171 |
id = 'search_box' |
|
809 | 172 |
|
0 | 173 |
visible = True # enabled by default |
174 |
title = _('search') |
|
175 |
order = 0 |
|
176 |
formdef = u"""<form action="%s"> |
|
177 |
<table id="tsearch"><tr><td> |
|
178 |
<input id="norql" type="text" accesskey="q" tabindex="%s" title="search text" value="%s" name="rql" /> |
|
179 |
<input type="hidden" name="__fromsearchbox" value="1" /> |
|
180 |
<input type="hidden" name="subvid" value="tsearch" /> |
|
181 |
</td><td> |
|
852
105893288777
simplify css style
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
536
diff
changeset
|
182 |
<input tabindex="%s" type="submit" id="rqlboxsubmit" class="rqlsubmit" value="" /> |
0 | 183 |
</td></tr></table> |
184 |
</form>""" |
|
185 |
||
186 |
def call(self, view=None, **kwargs): |
|
187 |
req = self.req |
|
188 |
if req.form.pop('__fromsearchbox', None): |
|
189 |
rql = req.form.get('rql', '') |
|
190 |
else: |
|
191 |
rql = '' |
|
192 |
form = self.formdef % (req.build_url('view'), req.next_tabindex(), |
|
193 |
html_escape(rql), req.next_tabindex()) |
|
194 |
title = u"""<span onclick="javascript: toggleVisibility('rqlinput')">%s</span>""" % req._(self.title) |
|
195 |
box = BoxWidget(title, self.id, _class="searchBoxFrame", islist=False, escape=False) |
|
196 |
box.append(BoxHtml(form)) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
197 |
box.render(self.w) |
0 | 198 |
|
199 |
||
200 |
# boxes disabled by default ################################################### |
|
201 |
||
202 |
class PossibleViewsBox(BoxTemplate): |
|
203 |
"""display a box containing links to all possible views""" |
|
204 |
id = 'possible_views_box' |
|
809 | 205 |
__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
|
206 |
|
809 | 207 |
visible = False |
0 | 208 |
title = _('possible views') |
209 |
order = 10 |
|
210 |
||
211 |
def call(self, **kwargs): |
|
212 |
box = BoxWidget(self.req._(self.title), self.id) |
|
613 | 213 |
views = [v for v in self.vreg.possible_views(self.req, self.rset) |
214 |
if v.category != 'startupview'] |
|
215 |
for category, views in self.sort_actions(views): |
|
0 | 216 |
menu = BoxMenu(category) |
613 | 217 |
for view in views: |
218 |
menu.append(self.box_action(view)) |
|
0 | 219 |
box.append(menu) |
220 |
if not box.is_empty(): |
|
221 |
box.render(self.w) |
|
222 |
||
125
979dbe0cade3
views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
107
diff
changeset
|
223 |
|
0 | 224 |
class StartupViewsBox(BoxTemplate): |
225 |
"""display a box containing links to all startup views""" |
|
226 |
id = 'startup_views_box' |
|
227 |
visible = False # disabled by default |
|
228 |
title = _('startup views') |
|
229 |
order = 70 |
|
230 |
||
231 |
def call(self, **kwargs): |
|
232 |
box = BoxWidget(self.req._(self.title), self.id) |
|
233 |
for view in self.vreg.possible_views(self.req, None): |
|
234 |
if view.category == 'startupview': |
|
235 |
box.append(self.box_action(view)) |
|
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
236 |
|
0 | 237 |
if not box.is_empty(): |
238 |
box.render(self.w) |
|
239 |
||
1263 | 240 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
241 |
# helper classes ############################################################## |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
242 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
243 |
class SideBoxView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
244 |
"""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
|
245 |
id = 'sidebox' |
1450
8edb0806dde4
fix relation_mode implementation, remove trailing spaces
sylvain.thenault@logilab.fr
parents:
1285
diff
changeset
|
246 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
247 |
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
|
248 |
"""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
|
249 |
if 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="sideBoxTitle"><span>%s</span></div>' % title) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
251 |
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
|
252 |
# 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
|
253 |
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
|
254 |
if self.rset.rowcount <= maxrelated: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
255 |
if len(self.rset) == 1: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
256 |
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
|
257 |
elif 1 < len(self.rset) < 5: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
258 |
self.wview('csv', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
259 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
260 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
261 |
# 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
|
262 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
263 |
self.rset.limit(maxrelated) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
264 |
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
|
265 |
self.wview('simplelist', self.rset) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
266 |
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
|
267 |
self.req._('see them all'))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
811
diff
changeset
|
268 |
self.w(u'</div>\n</div>\n') |