author | Sandrine Ribeau <sandrine.ribeau@logilab.fr> |
Wed, 22 Apr 2009 21:45:08 -0700 | |
changeset 1442 | db4e2508082b |
parent 1431 | 07614fd4722a |
child 1456 | 998ff29c3390 |
permissions | -rw-r--r-- |
0 | 1 |
"""Set of HTML generic base views: |
2 |
||
3 |
* noresult, final |
|
4 |
* primary, sidebox |
|
5 |
* secondary, oneline, incontext, outofcontext, text |
|
6 |
* list |
|
7 |
* xml, rss |
|
8 |
||
9 |
||
10 |
:organization: Logilab |
|
479 | 11 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 12 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
13 |
""" |
|
964
a711c7c185d1
gargl, this shouldn't be there in case we're running py 2.4
sylvain.thenault@logilab.fr
parents:
958
diff
changeset
|
14 |
#from __future__ import with_statement |
958
6053622aae81
fix name error, filter out non empty rset
sylvain.thenault@logilab.fr
parents:
956
diff
changeset
|
15 |
|
0 | 16 |
__docformat__ = "restructuredtext en" |
17 |
||
528
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
18 |
from warnings import warn |
0 | 19 |
from time import timezone |
20 |
||
21 |
from rql import nodes |
|
22 |
||
23 |
from logilab.common.decorators import cached |
|
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
24 |
from logilab.mtconverter import TransformError, html_escape, xml_escape |
0 | 25 |
|
26 |
from cubicweb import Unauthorized, NoSelectableObject, typed_eid |
|
431 | 27 |
from cubicweb.common.selectors import (yes, nonempty_rset, accept, |
323 | 28 |
one_line_rset, match_search_state, |
431 | 29 |
match_form_params, accept_rset) |
0 | 30 |
from cubicweb.common.uilib import (cut, printable_value, UnicodeCSVWriter, |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
31 |
ajax_replace_url, rql_for_eid, simple_sgml_tag) |
0 | 32 |
from cubicweb.common.view import EntityView, AnyRsetView, EmptyRsetView |
33 |
from cubicweb.web.httpcache import MaxAgeHTTPCacheManager |
|
34 |
from cubicweb.web.views import vid_from_rset, linksearch_select_url, linksearch_match |
|
35 |
||
36 |
_ = unicode |
|
37 |
||
38 |
class NullView(AnyRsetView): |
|
39 |
"""default view when no result has been found""" |
|
40 |
id = 'null' |
|
237
3df2e0ae2eba
begin selector renaming (work in progress)
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
213
diff
changeset
|
41 |
__select__ = classmethod(yes) |
0 | 42 |
def call(self, **kwargs): |
43 |
pass |
|
44 |
cell_call = call |
|
45 |
||
46 |
||
47 |
class NoResultView(EmptyRsetView): |
|
48 |
"""default view when no result has been found""" |
|
49 |
id = 'noresult' |
|
50 |
||
51 |
def call(self, **kwargs): |
|
52 |
self.w(u'<div class="searchMessage"><strong>%s</strong></div>\n' |
|
53 |
% self.req._('No result matching query')) |
|
54 |
||
55 |
||
56 |
class FinalView(AnyRsetView): |
|
57 |
"""display values without any transformation (i.e. get a number for |
|
58 |
entities) |
|
59 |
""" |
|
60 |
id = 'final' |
|
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
61 |
# record generated i18n catalog messages |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
62 |
_('%d years') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
63 |
_('%d months') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
64 |
_('%d weeks') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
65 |
_('%d days') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
66 |
_('%d hours') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
67 |
_('%d minutes') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
68 |
_('%d seconds') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
69 |
_('%d years') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
70 |
_('%d months') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
71 |
_('%d weeks') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
72 |
_('%d days') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
73 |
_('%d hours') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
74 |
_('%d minutes') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
75 |
_('%d seconds') |
0 | 76 |
|
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
77 |
def cell_call(self, row, col, props=None, displaytime=False, format='text/html'): |
0 | 78 |
etype = self.rset.description[row][col] |
79 |
value = self.rset.rows[row][col] |
|
80 |
if etype == 'String': |
|
81 |
entity, rtype = self.rset.related_entity(row, col) |
|
82 |
if entity is not None: |
|
83 |
# yes ! |
|
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
84 |
self.w(entity.printable_value(rtype, value, format=format)) |
0 | 85 |
return |
86 |
if etype in ('Time', 'Interval'): |
|
87 |
# value is DateTimeDelta but we have no idea about what is the |
|
88 |
# reference date here, so we can only approximate years and months |
|
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
89 |
if format == 'text/html': |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
90 |
space = ' ' |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
91 |
else: |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
92 |
space = ' ' |
0 | 93 |
if value.days > 730: # 2 years |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
94 |
self.w(self.req.__('%%d%syears' % space) % (value.days // 365)) |
0 | 95 |
elif value.days > 60: # 2 months |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
96 |
self.w(self.req.__('%%d%smonths' % space) % (value.days // 30)) |
0 | 97 |
elif value.days > 14: # 2 weeks |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
98 |
self.w(self.req.__('%%d%sweeks' % space) % (value.days // 7)) |
0 | 99 |
elif value.days > 2: |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
100 |
self.w(self.req.__('%%d%sdays' % space) % int(value.days)) |
0 | 101 |
elif value.hours > 2: |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
102 |
self.w(self.req.__('%%d%shours' % space) % int(value.hours)) |
0 | 103 |
elif value.minutes >= 2: |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
104 |
self.w(self.req.__('%%d%sminutes' % space) % int(value.minutes)) |
0 | 105 |
else: |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
106 |
self.w(self.req.__('%%d%sseconds' % space) % int(value.seconds)) |
0 | 107 |
return |
108 |
self.wdata(printable_value(self.req, etype, value, props, displaytime=displaytime)) |
|
109 |
||
110 |
||
111 |
class EditableFinalView(FinalView): |
|
112 |
"""same as FinalView but enables inplace-edition when possible""" |
|
113 |
id = 'editable-final' |
|
114 |
||
115 |
def cell_call(self, row, col, props=None, displaytime=False): |
|
116 |
etype = self.rset.description[row][col] |
|
117 |
value = self.rset.rows[row][col] |
|
118 |
entity, rtype = self.rset.related_entity(row, col) |
|
119 |
if entity is not None: |
|
120 |
self.w(entity.view('reledit', rtype=rtype)) |
|
121 |
else: |
|
122 |
super(EditableFinalView, self).cell_call(row, col, props, displaytime) |
|
123 |
||
124 |
PRIMARY_SKIP_RELS = set(['is', 'is_instance_of', 'identity', |
|
125 |
'owned_by', 'created_by', |
|
126 |
'in_state', 'wf_info_for', 'require_permission', |
|
127 |
'from_entity', 'to_entity', |
|
128 |
'see_also']) |
|
129 |
||
130 |
class PrimaryView(EntityView): |
|
131 |
"""the full view of an non final entity""" |
|
132 |
id = 'primary' |
|
133 |
title = _('primary') |
|
134 |
show_attr_label = True |
|
135 |
show_rel_label = True |
|
136 |
skip_none = True |
|
137 |
skip_attrs = ('eid', 'creation_date', 'modification_date') |
|
138 |
skip_rels = () |
|
139 |
main_related_section = True |
|
140 |
||
141 |
def html_headers(self): |
|
142 |
"""return a list of html headers (eg something to be inserted between |
|
143 |
<head> and </head> of the returned page |
|
144 |
||
145 |
by default primary views are indexed |
|
146 |
""" |
|
147 |
return [] |
|
148 |
||
149 |
def cell_call(self, row, col): |
|
150 |
self.row = row |
|
213
6842c3dee34b
adding files (formely appearing in jpl) specific to cubicweb
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
179
diff
changeset
|
151 |
# XXX move render_entity implementation here |
0 | 152 |
self.render_entity(self.complete_entity(row, col)) |
153 |
||
154 |
def render_entity(self, entity): |
|
155 |
"""return html to display the given entity""" |
|
156 |
siderelations = [] |
|
157 |
self.render_entity_title(entity) |
|
158 |
self.render_entity_metadata(entity) |
|
159 |
# entity's attributes and relations, excluding meta data |
|
160 |
# if the entity isn't meta itself |
|
1413
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
161 |
boxes = self._preinit_side_related(entity) or siderelations |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
162 |
if boxes: |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
163 |
self.w(u'<table width="100%"><tr><td width="75%">') |
988
b73f3cd23d43
remplacing tables by div for right (and left) box layout
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
978
diff
changeset
|
164 |
self.w(u'<div>') |
0 | 165 |
self.w(u'<div class="mainInfo">') |
166 |
self.render_entity_attributes(entity, siderelations) |
|
167 |
self.w(u'</div>') |
|
528
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
168 |
self.content_navigation_components('navcontenttop') |
0 | 169 |
if self.main_related_section: |
170 |
self.render_entity_relations(entity, siderelations) |
|
988
b73f3cd23d43
remplacing tables by div for right (and left) box layout
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
978
diff
changeset
|
171 |
self.w(u'</div>') |
1413
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
172 |
if boxes: |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
173 |
self.w(u'</td><td>') |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
174 |
# side boxes |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
175 |
self.w(u'<div class="primaryRight">') |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
176 |
self.render_side_related(entity, siderelations) |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
177 |
self.w(u'</div>') |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
178 |
self.w(u'</td></tr></table>') |
528
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
179 |
self.content_navigation_components('navcontentbottom') |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
180 |
|
1413
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
181 |
|
528
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
182 |
def content_navigation_components(self, context): |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
183 |
self.w(u'<div class="%s">' % context) |
0 | 184 |
for comp in self.vreg.possible_vobjects('contentnavigation', |
528
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
185 |
self.req, self.rset, row=self.row, |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
186 |
view=self, context=context): |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
187 |
try: |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
188 |
comp.dispatch(w=self.w, row=self.row, view=self) |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
189 |
except NotImplementedError: |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
190 |
warn('component %s doesnt implement cell_call, please update' |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
191 |
% comp.__class__, DeprecationWarning) |
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
192 |
comp.dispatch(w=self.w, view=self) |
0 | 193 |
self.w(u'</div>') |
528
60bd171ecd04
give row when selecting/dispatching content navigation component
sylvain.thenault@logilab.fr
parents:
479
diff
changeset
|
194 |
|
0 | 195 |
def iter_attributes(self, entity): |
196 |
for rschema, targetschema in entity.e_schema.attribute_definitions(): |
|
197 |
attr = rschema.type |
|
198 |
if attr in self.skip_attrs: |
|
199 |
continue |
|
200 |
yield rschema, targetschema |
|
201 |
||
202 |
def iter_relations(self, entity): |
|
203 |
skip = set(self.skip_rels) |
|
204 |
skip.update(PRIMARY_SKIP_RELS) |
|
205 |
for rschema, targetschemas, x in entity.e_schema.relation_definitions(): |
|
206 |
if rschema.type in skip: |
|
207 |
continue |
|
208 |
yield rschema, targetschemas, x |
|
209 |
||
210 |
def render_entity_title(self, entity): |
|
211 |
title = self.content_title(entity) # deprecate content_title? |
|
212 |
if title: |
|
213 |
self.w(u'<h1><span class="etype">%s</span> %s</h1>' |
|
214 |
% (entity.dc_type().capitalize(), title)) |
|
215 |
||
216 |
def content_title(self, entity): |
|
217 |
"""default implementation return an empty string""" |
|
218 |
return u'' |
|
219 |
||
220 |
def render_entity_metadata(self, entity): |
|
221 |
entity.view('metadata', w=self.w) |
|
222 |
summary = self.summary(entity) # deprecate summary? |
|
223 |
if summary: |
|
224 |
self.w(u'<div class="summary">%s</div>' % summary) |
|
225 |
||
226 |
def summary(self, entity): |
|
227 |
"""default implementation return an empty string""" |
|
179 | 228 |
return u'' |
0 | 229 |
|
230 |
def render_entity_attributes(self, entity, siderelations): |
|
231 |
for rschema, targetschema in self.iter_attributes(entity): |
|
232 |
attr = rschema.type |
|
233 |
if targetschema.type in ('Password', 'Bytes'): |
|
234 |
continue |
|
235 |
try: |
|
236 |
wdg = entity.get_widget(attr) |
|
237 |
except Exception, ex: |
|
238 |
value = entity.printable_value(attr, entity[attr], targetschema.type) |
|
239 |
else: |
|
240 |
value = wdg.render(entity) |
|
241 |
if self.skip_none and (value is None or value == ''): |
|
242 |
continue |
|
243 |
if rschema.meta: |
|
244 |
continue |
|
245 |
self._render_related_entities(entity, rschema, value) |
|
246 |
||
247 |
def render_entity_relations(self, entity, siderelations): |
|
248 |
if hasattr(self, 'get_side_boxes_defs'): |
|
249 |
return |
|
250 |
eschema = entity.e_schema |
|
251 |
maxrelated = self.req.property_value('navigation.related-limit') |
|
252 |
for rschema, targetschemas, x in self.iter_relations(entity): |
|
253 |
try: |
|
254 |
related = entity.related(rschema.type, x, limit=maxrelated+1) |
|
255 |
except Unauthorized: |
|
256 |
continue |
|
257 |
if not related: |
|
258 |
continue |
|
259 |
if self.is_side_related(rschema, eschema): |
|
260 |
siderelations.append((rschema, related, x)) |
|
261 |
continue |
|
262 |
self._render_related_entities(entity, rschema, related, x) |
|
263 |
||
1413
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
264 |
def _preinit_side_related(self, entity): |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
265 |
self._sideboxes = None |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
266 |
if hasattr(self, 'get_side_boxes_defs'): |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
267 |
self._sideboxes = [(label, rset) for label, rset in self.get_side_boxes_defs(entity) |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
268 |
if rset] |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
269 |
self._boxes_in_context = list(self.vreg.possible_vobjects('boxes', self.req, self.rset, |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
270 |
row=self.row, view=self, |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
271 |
context='incontext')) |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
272 |
return self._sideboxes or self._boxes_in_context |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
273 |
|
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
274 |
|
0 | 275 |
def render_side_related(self, entity, siderelations): |
276 |
"""display side related relations: |
|
277 |
non-meta in a first step, meta in a second step |
|
278 |
""" |
|
1413
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
279 |
if self._sideboxes: |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
280 |
for label, rset in self._sideboxes: |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
281 |
self.w(u'<div class="sideRelated">') |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
282 |
self.wview('sidebox', rset, title=label) |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
283 |
self.w(u'</div>') |
0 | 284 |
elif siderelations: |
285 |
self.w(u'<div class="sideRelated">') |
|
286 |
for relatedinfos in siderelations: |
|
287 |
# if not relatedinfos[0].meta: |
|
288 |
# continue |
|
289 |
self._render_related_entities(entity, *relatedinfos) |
|
290 |
self.w(u'</div>') |
|
1413
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
291 |
|
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
292 |
if self._boxes_in_context: |
ad19d7e6a291
create a table for siderelation
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1194
diff
changeset
|
293 |
for box in self._boxes_in_context: |
953
ded89d49c0b4
xhtml fixes: table has no align attribute, avoid inserting empty table
sylvain.thenault@logilab.fr
parents:
925
diff
changeset
|
294 |
try: |
ded89d49c0b4
xhtml fixes: table has no align attribute, avoid inserting empty table
sylvain.thenault@logilab.fr
parents:
925
diff
changeset
|
295 |
box.dispatch(w=self.w, row=self.row) |
ded89d49c0b4
xhtml fixes: table has no align attribute, avoid inserting empty table
sylvain.thenault@logilab.fr
parents:
925
diff
changeset
|
296 |
except NotImplementedError: |
ded89d49c0b4
xhtml fixes: table has no align attribute, avoid inserting empty table
sylvain.thenault@logilab.fr
parents:
925
diff
changeset
|
297 |
# much probably a context insensitive box, which only implements |
ded89d49c0b4
xhtml fixes: table has no align attribute, avoid inserting empty table
sylvain.thenault@logilab.fr
parents:
925
diff
changeset
|
298 |
# .call() and not cell_call() |
991
746fed01d1e0
correction (removing comments)
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
988
diff
changeset
|
299 |
box.dispatch(w=self.w) |
0 | 300 |
|
301 |
def is_side_related(self, rschema, eschema): |
|
302 |
return rschema.meta and \ |
|
303 |
not rschema.schema_relation() == eschema.schema_entity() |
|
304 |
||
305 |
def _render_related_entities(self, entity, rschema, related, |
|
306 |
role='subject'): |
|
307 |
if rschema.is_final(): |
|
308 |
value = related |
|
309 |
show_label = self.show_attr_label |
|
310 |
else: |
|
311 |
if not related: |
|
312 |
return |
|
313 |
show_label = self.show_rel_label |
|
314 |
# if not too many entities, show them all in a list |
|
315 |
maxrelated = self.req.property_value('navigation.related-limit') |
|
316 |
if related.rowcount <= maxrelated: |
|
317 |
if related.rowcount == 1: |
|
318 |
value = self.view('incontext', related, row=0) |
|
319 |
elif 1 < related.rowcount <= 5: |
|
320 |
value = self.view('csv', related) |
|
321 |
else: |
|
322 |
value = '<div>' + self.view('simplelist', related) + '</div>' |
|
323 |
# else show links to display related entities |
|
324 |
else: |
|
325 |
rql = related.printable_rql() |
|
326 |
related.limit(maxrelated) |
|
327 |
value = '<div>' + self.view('simplelist', related) |
|
328 |
value += '[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
|
329 |
self.req._('see them all')) |
|
330 |
value += '</div>' |
|
331 |
label = display_name(self.req, rschema.type, role) |
|
332 |
self.field(label, value, show_label=show_label, w=self.w, tr=False) |
|
333 |
||
334 |
||
335 |
class SideBoxView(EntityView): |
|
336 |
"""side box usually displaying some related entities in a primary view""" |
|
337 |
id = 'sidebox' |
|
338 |
||
339 |
def call(self, boxclass='sideBox', title=u''): |
|
340 |
"""display a list of entities by calling their <item_vid> view |
|
341 |
""" |
|
342 |
if title: |
|
343 |
self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % title) |
|
344 |
self.w(u'<div class="%s"><div class="sideBoxBody">' % boxclass) |
|
345 |
# if not too much entities, show them all in a list |
|
346 |
maxrelated = self.req.property_value('navigation.related-limit') |
|
347 |
if self.rset.rowcount <= maxrelated: |
|
348 |
if len(self.rset) == 1: |
|
349 |
self.wview('incontext', self.rset, row=0) |
|
350 |
elif 1 < len(self.rset) < 5: |
|
351 |
self.wview('csv', self.rset) |
|
352 |
else: |
|
353 |
self.wview('simplelist', self.rset) |
|
354 |
# else show links to display related entities |
|
355 |
else: |
|
356 |
self.rset.limit(maxrelated) |
|
357 |
rql = self.rset.printable_rql(encoded=False) |
|
358 |
self.wview('simplelist', self.rset) |
|
359 |
self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql), |
|
360 |
self.req._('see them all'))) |
|
361 |
self.w(u'</div>\n</div>\n') |
|
362 |
||
363 |
||
364 |
||
365 |
class SecondaryView(EntityView): |
|
366 |
id = 'secondary' |
|
367 |
title = _('secondary') |
|
368 |
||
369 |
def cell_call(self, row, col): |
|
370 |
"""the secondary view for an entity |
|
371 |
secondary = icon + view(oneline) |
|
372 |
""" |
|
373 |
entity = self.entity(row, col) |
|
374 |
self.w(u' ') |
|
375 |
self.wview('oneline', self.rset, row=row, col=col) |
|
376 |
||
377 |
class OneLineView(EntityView): |
|
378 |
id = 'oneline' |
|
379 |
title = _('oneline') |
|
380 |
||
381 |
def cell_call(self, row, col): |
|
382 |
"""the one line view for an entity: linked text view |
|
383 |
""" |
|
384 |
entity = self.entity(row, col) |
|
385 |
self.w(u'<a href="%s">' % html_escape(entity.absolute_url())) |
|
386 |
self.w(html_escape(self.view('text', self.rset, row=row, col=col))) |
|
387 |
self.w(u'</a>') |
|
388 |
||
389 |
class TextView(EntityView): |
|
532
ce3e94cbb074
specify content type for text views
sylvain.thenault@logilab.fr
parents:
531
diff
changeset
|
390 |
"""the simplest text view for an entity""" |
0 | 391 |
id = 'text' |
392 |
title = _('text') |
|
532
ce3e94cbb074
specify content type for text views
sylvain.thenault@logilab.fr
parents:
531
diff
changeset
|
393 |
content_type = 'text/plain' |
0 | 394 |
accepts = 'Any', |
395 |
def call(self, **kwargs): |
|
396 |
"""the view is called for an entire result set, by default loop |
|
397 |
other rows of the result set and call the same view on the |
|
398 |
particular row |
|
399 |
||
400 |
Views applicable on None result sets have to override this method |
|
401 |
""" |
|
402 |
rset = self.rset |
|
403 |
if rset is None: |
|
404 |
raise NotImplementedError, self |
|
405 |
for i in xrange(len(rset)): |
|
406 |
self.wview(self.id, rset, row=i, **kwargs) |
|
407 |
if len(rset) > 1: |
|
408 |
self.w(u"\n") |
|
409 |
||
410 |
def cell_call(self, row, col=0, **kwargs): |
|
411 |
entity = self.entity(row, col) |
|
412 |
self.w(cut(entity.dc_title(), |
|
413 |
self.req.property_value('navigation.short-line-size'))) |
|
414 |
||
137
7e45cf48c2f1
don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
415 |
|
0 | 416 |
class MetaDataView(EntityView): |
417 |
"""paragraph view of some metadata""" |
|
418 |
id = 'metadata' |
|
419 |
accepts = 'Any', |
|
420 |
show_eid = True |
|
421 |
||
422 |
def cell_call(self, row, col): |
|
423 |
_ = self.req._ |
|
424 |
entity = self.entity(row, col) |
|
425 |
self.w(u'<div class="metadata">') |
|
426 |
if self.show_eid: |
|
427 |
self.w(u'#%s - ' % entity.eid) |
|
428 |
if entity.modification_date != entity.creation_date: |
|
429 |
self.w(u'<span>%s</span> ' % _('latest update on')) |
|
430 |
self.w(u'<span class="value">%s</span>, ' |
|
431 |
% self.format_date(entity.modification_date)) |
|
432 |
# entities from external source may not have a creation date (eg ldap) |
|
433 |
if entity.creation_date: |
|
434 |
self.w(u'<span>%s</span> ' % _('created on')) |
|
435 |
self.w(u'<span class="value">%s</span>' |
|
436 |
% self.format_date(entity.creation_date)) |
|
437 |
if entity.creator: |
|
438 |
self.w(u' <span>%s</span> ' % _('by')) |
|
439 |
self.w(u'<span class="value">%s</span>' % entity.creator.name()) |
|
440 |
self.w(u'</div>') |
|
441 |
||
442 |
||
443 |
# new default views for finner control in general views , to use instead of |
|
444 |
# oneline / secondary |
|
445 |
||
446 |
class InContextTextView(TextView): |
|
447 |
id = 'textincontext' |
|
448 |
title = None # not listed as a possible view |
|
449 |
def cell_call(self, row, col): |
|
450 |
entity = self.entity(row, col) |
|
451 |
self.w(entity.dc_title()) |
|
452 |
||
453 |
class OutOfContextTextView(InContextTextView): |
|
454 |
id = 'textoutofcontext' |
|
455 |
||
456 |
def cell_call(self, row, col): |
|
457 |
entity = self.entity(row, col) |
|
458 |
self.w(entity.dc_long_title()) |
|
459 |
||
460 |
||
461 |
class InContextView(EntityView): |
|
462 |
id = 'incontext' |
|
463 |
||
464 |
def cell_call(self, row, col): |
|
465 |
entity = self.entity(row, col) |
|
466 |
desc = cut(entity.dc_description(), 50) |
|
467 |
self.w(u'<a href="%s" title="%s">' % (html_escape(entity.absolute_url()), |
|
468 |
html_escape(desc))) |
|
469 |
self.w(html_escape(self.view('textincontext', self.rset, row=row, col=col))) |
|
470 |
self.w(u'</a>') |
|
471 |
||
472 |
||
473 |
class OutOfContextView(EntityView): |
|
474 |
id = 'outofcontext' |
|
475 |
||
476 |
def cell_call(self, row, col): |
|
477 |
self.w(u'<a href="%s">' % self.entity(row, col).absolute_url()) |
|
478 |
self.w(html_escape(self.view('textoutofcontext', self.rset, row=row, col=col))) |
|
479 |
self.w(u'</a>') |
|
480 |
||
481 |
class NotClickableInContextView(EntityView): |
|
482 |
id = 'incontext' |
|
483 |
accepts = ('State',) |
|
484 |
def cell_call(self, row, col): |
|
485 |
self.w(html_escape(self.view('textincontext', self.rset, row=row, col=col))) |
|
486 |
||
487 |
## class NotClickableOutOfContextView(EntityView): |
|
488 |
## id = 'outofcontext' |
|
489 |
## accepts = ('State',) |
|
490 |
## def cell_call(self, row, col): |
|
491 |
## self.w(html_escape(self.view('textoutofcontext', self.rset, row=row))) |
|
492 |
||
493 |
||
494 |
# list and table related views ################################################ |
|
495 |
||
496 |
class ListView(EntityView): |
|
497 |
id = 'list' |
|
498 |
title = _('list') |
|
499 |
item_vid = 'listitem' |
|
500 |
||
501 |
def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs): |
|
502 |
"""display a list of entities by calling their <item_vid> view |
|
503 |
|
|
504 |
:param listid: the DOM id to use for the root element |
|
505 |
""" |
|
506 |
if subvid is None and 'subvid' in self.req.form: |
|
507 |
subvid = self.req.form.pop('subvid') # consume it |
|
508 |
if listid: |
|
509 |
listid = u' id="%s"' % listid |
|
510 |
else: |
|
511 |
listid = u'' |
|
512 |
if title: |
|
513 |
self.w(u'<div%s class="%s"><h4>%s</h4>\n' % (listid, klass or 'section', title)) |
|
514 |
self.w(u'<ul>\n') |
|
515 |
else: |
|
516 |
self.w(u'<ul%s class="%s">\n' % (listid, klass or 'section')) |
|
517 |
for i in xrange(self.rset.rowcount): |
|
518 |
self.cell_call(row=i, col=0, vid=subvid, **kwargs) |
|
519 |
self.w(u'</ul>\n') |
|
520 |
if title: |
|
521 |
self.w(u'</div>\n') |
|
522 |
||
523 |
def cell_call(self, row, col=0, vid=None, **kwargs): |
|
524 |
self.w(u'<li>') |
|
525 |
self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs) |
|
526 |
self.w(u'</li>\n') |
|
527 |
||
528 |
def url(self): |
|
529 |
"""overrides url method so that by default, the view list is called |
|
530 |
with sorted entities |
|
531 |
""" |
|
532 |
coltypes = self.rset.column_types(0) |
|
533 |
# don't want to generate the rql if there is some restriction on |
|
534 |
# something else than the entity type |
|
535 |
if len(coltypes) == 1: |
|
536 |
# XXX norestriction is not correct here. For instance, in cases like |
|
537 |
# Any P,N WHERE P is Project, P name N |
|
538 |
# norestriction should equal True |
|
539 |
restr = self.rset.syntax_tree().children[0].where |
|
540 |
norestriction = (isinstance(restr, nodes.Relation) and |
|
541 |
restr.is_types_restriction()) |
|
542 |
if norestriction: |
|
543 |
etype = iter(coltypes).next() |
|
544 |
return self.build_url(etype.lower(), vid=self.id) |
|
545 |
if len(self.rset) == 1: |
|
546 |
entity = self.rset.get_entity(0, 0) |
|
547 |
return self.build_url(entity.rest_path(), vid=self.id) |
|
548 |
return self.build_url(rql=self.rset.printable_rql(), vid=self.id) |
|
549 |
||
550 |
||
551 |
class ListItemView(EntityView): |
|
552 |
id = 'listitem' |
|
553 |
||
554 |
@property |
|
555 |
def redirect_vid(self): |
|
556 |
if self.req.search_state[0] == 'normal': |
|
557 |
return 'outofcontext' |
|
558 |
return 'outofcontext-search' |
|
559 |
||
560 |
def cell_call(self, row, col, vid=None, **kwargs): |
|
561 |
if not vid: |
|
562 |
vid = self.redirect_vid |
|
563 |
try: |
|
564 |
self.wview(vid, self.rset, row=row, col=col, **kwargs) |
|
565 |
except NoSelectableObject: |
|
566 |
if vid == self.redirect_vid: |
|
567 |
raise |
|
568 |
self.wview(self.redirect_vid, self.rset, row=row, col=col, **kwargs) |
|
569 |
||
570 |
||
571 |
class SimpleListView(ListItemView): |
|
572 |
"""list without bullets""" |
|
573 |
id = 'simplelist' |
|
574 |
redirect_vid = 'incontext' |
|
575 |
||
576 |
||
577 |
class CSVView(SimpleListView): |
|
578 |
id = 'csv' |
|
579 |
redirect_vid = 'incontext' |
|
580 |
||
581 |
def call(self, **kwargs): |
|
582 |
rset = self.rset |
|
583 |
for i in xrange(len(rset)): |
|
584 |
self.cell_call(i, 0, vid=kwargs.get('vid')) |
|
585 |
if i < rset.rowcount-1: |
|
586 |
self.w(u", ") |
|
587 |
||
588 |
||
589 |
class TreeItemView(ListItemView): |
|
590 |
accepts = ('Any',) |
|
591 |
id = 'treeitem' |
|
592 |
||
593 |
def cell_call(self, row, col): |
|
594 |
self.wview('incontext', self.rset, row=row, col=col) |
|
595 |
||
596 |
||
597 |
# xml and xml/rss views ####################################################### |
|
598 |
||
599 |
class XmlView(EntityView): |
|
600 |
id = 'xml' |
|
601 |
title = _('xml') |
|
602 |
templatable = False |
|
603 |
content_type = 'text/xml' |
|
604 |
xml_root = 'rset' |
|
605 |
item_vid = 'xmlitem' |
|
606 |
||
607 |
def cell_call(self, row, col): |
|
608 |
self.wview(self.item_vid, self.rset, row=row, col=col) |
|
609 |
||
610 |
def call(self): |
|
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
611 |
"""display a list of entities by calling their <item_vid> view""" |
0 | 612 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
613 |
self.w(u'<%s size="%s">\n' % (self.xml_root, len(self.rset))) |
|
614 |
for i in xrange(self.rset.rowcount): |
|
615 |
self.cell_call(i, 0) |
|
616 |
self.w(u'</%s>\n' % self.xml_root) |
|
617 |
||
618 |
||
619 |
class XmlItemView(EntityView): |
|
620 |
id = 'xmlitem' |
|
621 |
||
622 |
def cell_call(self, row, col): |
|
623 |
""" element as an item for an xml feed """ |
|
624 |
entity = self.complete_entity(row, col) |
|
625 |
self.w(u'<%s>\n' % (entity.e_schema)) |
|
626 |
for rschema, attrschema in entity.e_schema.attribute_definitions(): |
|
627 |
attr = rschema.type |
|
628 |
try: |
|
629 |
value = entity[attr] |
|
630 |
except KeyError: |
|
631 |
# Bytes |
|
632 |
continue |
|
633 |
if value is not None: |
|
634 |
if attrschema == 'Bytes': |
|
635 |
from base64 import b64encode |
|
636 |
value = '<![CDATA[%s]]>' % b64encode(value.getvalue()) |
|
637 |
elif isinstance(value, basestring): |
|
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
638 |
value = xml_escape(value) |
0 | 639 |
self.w(u' <%s>%s</%s>\n' % (attr, value, attr)) |
640 |
self.w(u'</%s>\n' % (entity.e_schema)) |
|
641 |
||
642 |
||
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
643 |
|
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
644 |
class XMLRsetView(AnyRsetView): |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
645 |
"""dumps xml in CSV""" |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
646 |
id = 'rsetxml' |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
647 |
title = _('xml export') |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
648 |
templatable = False |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
649 |
content_type = 'text/xml' |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
650 |
xml_root = 'rset' |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
651 |
|
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
652 |
def call(self): |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
653 |
w = self.w |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
654 |
rset, descr = self.rset, self.rset.description |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
655 |
eschema = self.schema.eschema |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
656 |
labels = self.columns_labels(False) |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
657 |
w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
658 |
w(u'<%s query="%s">\n' % (self.xml_root, html_escape(rset.printable_rql()))) |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
659 |
for rowindex, row in enumerate(self.rset): |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
660 |
w(u' <row>\n') |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
661 |
for colindex, val in enumerate(row): |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
662 |
etype = descr[rowindex][colindex] |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
663 |
tag = labels[colindex] |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
664 |
attrs = {} |
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
665 |
if '(' in tag: |
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
666 |
attrs['expr'] = tag |
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
667 |
tag = 'funccall' |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
668 |
if val is not None and not eschema(etype).is_final(): |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
669 |
attrs['eid'] = val |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
670 |
# csvrow.append(val) # val is eid in that case |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
671 |
val = self.view('textincontext', rset, |
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
672 |
row=rowindex, col=colindex) |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
673 |
else: |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
674 |
val = self.view('final', rset, displaytime=True, |
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
675 |
row=rowindex, col=colindex, format='text/plain') |
530
9b56df97ec5f
fix xml views: ensure we're generating valide tag names (rsetxml), protect against control characters in xml view (should probably be generalized...)
sylvain.thenault@logilab.fr
parents:
528
diff
changeset
|
676 |
w(simple_sgml_tag(tag, val, **attrs)) |
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
677 |
w(u' </row>\n') |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
678 |
w(u'</%s>\n' % self.xml_root) |
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
679 |
|
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
680 |
|
0 | 681 |
class RssView(XmlView): |
682 |
id = 'rss' |
|
683 |
title = _('rss') |
|
684 |
templatable = False |
|
685 |
content_type = 'text/xml' |
|
686 |
http_cache_manager = MaxAgeHTTPCacheManager |
|
687 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
|
1194
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
688 |
|
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
689 |
def _open(self): |
0 | 690 |
req = self.req |
691 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding) |
|
1125
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
692 |
self.w(u'''<rss version="2.0" |
0 | 693 |
xmlns:dc="http://purl.org/dc/elements/1.1/" |
1429
1d2a05685233
make the rss view valid (we should probably keep rdf:about on channel)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1427
diff
changeset
|
694 |
>\n''') |
1d2a05685233
make the rss view valid (we should probably keep rdf:about on channel)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1427
diff
changeset
|
695 |
self.w(u' <channel>\n') |
0 | 696 |
self.w(u' <title>%s RSS Feed</title>\n' % html_escape(self.page_title())) |
697 |
self.w(u' <description>%s</description>\n' % html_escape(req.form.get('vtitle', ''))) |
|
698 |
params = req.form.copy() |
|
699 |
params.pop('vid', None) |
|
700 |
self.w(u' <link>%s</link>\n' % html_escape(self.build_url(**params))) |
|
1194
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
701 |
|
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
702 |
def _close(self): |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
703 |
self.w(u' </channel>\n') |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
704 |
self.w(u'</rss>') |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
705 |
|
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
706 |
def call(self): |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
707 |
"""display a list of entities by calling their <item_vid> view""" |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
708 |
self._open() |
0 | 709 |
for i in xrange(self.rset.rowcount): |
710 |
self.cell_call(i, 0) |
|
1194
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
711 |
self._close() |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
712 |
|
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
713 |
def cell_call(self, row, col): |
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
714 |
self.wview('rssitem', self.rset, row=row, col=col) |
0 | 715 |
|
716 |
class RssItemView(EntityView): |
|
717 |
id = 'rssitem' |
|
718 |
date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600) |
|
1194
e224f064a268
optimize this code part
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1140
diff
changeset
|
719 |
add_div_section = False |
0 | 720 |
|
721 |
def cell_call(self, row, col): |
|
722 |
entity = self.complete_entity(row, col) |
|
1429
1d2a05685233
make the rss view valid (we should probably keep rdf:about on channel)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1427
diff
changeset
|
723 |
self.w(u'<item>\n') |
1d2a05685233
make the rss view valid (we should probably keep rdf:about on channel)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1427
diff
changeset
|
724 |
self.w(u'<guid isPermaLink="true">%s</guid>\n' % html_escape(entity.absolute_url())) |
1125
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
725 |
self.render_title_link(entity) |
1140
79bcbb1c39ce
please stop/read carefully dumb copy / past
sylvain.thenault@logilab.fr
parents:
1139
diff
changeset
|
726 |
self._marker('description', html_escape(entity.dc_description())) |
1125
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
727 |
self._marker('dc:date', entity.dc_date(self.date_format)) |
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
728 |
self.render_entity_creator(entity) |
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
729 |
self.w(u'</item>\n') |
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
730 |
|
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
731 |
def render_title_link(self, entity): |
0 | 732 |
self._marker('title', entity.dc_long_title()) |
733 |
self._marker('link', entity.absolute_url()) |
|
1125
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
734 |
|
1fbeb11a27a3
refactoring RssItemView.
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents:
991
diff
changeset
|
735 |
def render_entity_creator(self, entity): |
324
9b51dac0bac2
fix author tag
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
323
diff
changeset
|
736 |
if entity.creator: |
1431
07614fd4722a
user dc_creator for rss view
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1430
diff
changeset
|
737 |
self._marker('dc:creator', entity.dc_creator()) |
1427
b31f7abc3fdc
The same item should not include both author and dc:creator
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1413
diff
changeset
|
738 |
|
b31f7abc3fdc
The same item should not include both author and dc:creator
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1413
diff
changeset
|
739 |
|
0 | 740 |
def _marker(self, marker, value): |
741 |
if value: |
|
742 |
self.w(u' <%s>%s</%s>\n' % (marker, html_escape(value), marker)) |
|
743 |
||
744 |
class CSVMixIn(object): |
|
745 |
"""mixin class for CSV views""" |
|
746 |
templatable = False |
|
747 |
content_type = "text/comma-separated-values" |
|
748 |
binary = True # avoid unicode assertion |
|
749 |
csv_params = {'dialect': 'excel', |
|
750 |
'quotechar': '"', |
|
751 |
'delimiter': ';', |
|
752 |
'lineterminator': '\n'} |
|
753 |
||
754 |
def set_request_content_type(self): |
|
755 |
"""overriden to set a .csv filename""" |
|
756 |
self.req.set_content_type(self.content_type, filename='cubicwebexport.csv') |
|
757 |
||
758 |
def csvwriter(self, **kwargs): |
|
759 |
params = self.csv_params.copy() |
|
760 |
params.update(kwargs) |
|
761 |
return UnicodeCSVWriter(self.w, self.req.encoding, **params) |
|
762 |
||
763 |
||
764 |
class CSVRsetView(CSVMixIn, AnyRsetView): |
|
765 |
"""dumps rset in CSV""" |
|
766 |
id = 'csvexport' |
|
767 |
title = _('csv export') |
|
768 |
||
769 |
def call(self): |
|
770 |
writer = self.csvwriter() |
|
369
c8a6edc224bb
new rsetxml view, reusing most code from csvexport view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
349
diff
changeset
|
771 |
writer.writerow(self.columns_labels()) |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
772 |
rset, descr = self.rset, self.rset.description |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
773 |
eschema = self.schema.eschema |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
774 |
for rowindex, row in enumerate(rset): |
0 | 775 |
csvrow = [] |
776 |
for colindex, val in enumerate(row): |
|
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
777 |
etype = descr[rowindex][colindex] |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
778 |
if val is not None and not eschema(etype).is_final(): |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
779 |
# csvrow.append(val) # val is eid in that case |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
780 |
content = self.view('textincontext', rset, |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
781 |
row=rowindex, col=colindex) |
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
782 |
else: |
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
783 |
content = self.view('final', rset, |
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
784 |
displaytime=True, format='text/plain', |
370
7e76f651314b
fix rset xml view
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
369
diff
changeset
|
785 |
row=rowindex, col=colindex) |
0 | 786 |
csvrow.append(content) |
787 |
writer.writerow(csvrow) |
|
788 |
||
789 |
||
790 |
class CSVEntityView(CSVMixIn, EntityView): |
|
791 |
"""dumps rset's entities (with full set of attributes) in CSV""" |
|
792 |
id = 'ecsvexport' |
|
793 |
title = _('csv entities export') |
|
794 |
||
795 |
def call(self): |
|
796 |
""" |
|
797 |
the generated CSV file will have a table per entity type |
|
798 |
found in the resultset. ('table' here only means empty |
|
799 |
lines separation between table contents) |
|
800 |
""" |
|
801 |
req = self.req |
|
802 |
rows_by_type = {} |
|
803 |
writer = self.csvwriter() |
|
804 |
rowdef_by_type = {} |
|
805 |
for index in xrange(len(self.rset)): |
|
806 |
entity = self.complete_entity(index) |
|
807 |
if entity.e_schema not in rows_by_type: |
|
400
b05a36678265
'as' becomes a keyword when with statement activated
sylvain.thenault@logilab.fr
parents:
371
diff
changeset
|
808 |
rowdef_by_type[entity.e_schema] = [rs for rs, at in entity.e_schema.attribute_definitions() |
b05a36678265
'as' becomes a keyword when with statement activated
sylvain.thenault@logilab.fr
parents:
371
diff
changeset
|
809 |
if at != 'Bytes'] |
0 | 810 |
rows_by_type[entity.e_schema] = [[display_name(req, rschema.type) |
811 |
for rschema in rowdef_by_type[entity.e_schema]]] |
|
812 |
rows = rows_by_type[entity.e_schema] |
|
813 |
rows.append([entity.printable_value(rs.type, format='text/plain') |
|
814 |
for rs in rowdef_by_type[entity.e_schema]]) |
|
815 |
for etype, rows in rows_by_type.items(): |
|
816 |
writer.writerows(rows) |
|
817 |
# use two empty lines as separator |
|
818 |
writer.writerows([[], []]) |
|
819 |
||
820 |
||
821 |
## Work in progress ########################################################### |
|
822 |
||
823 |
class SearchForAssociationView(EntityView): |
|
824 |
"""view called by the edition view when the user asks |
|
825 |
to search for something to link to the edited eid |
|
826 |
""" |
|
827 |
id = 'search-associate' |
|
828 |
title = _('search for association') |
|
431 | 829 |
__selectors__ = (one_line_rset, match_search_state, accept) |
0 | 830 |
accepts = ('Any',) |
831 |
search_states = ('linksearch',) |
|
832 |
||
833 |
def cell_call(self, row, col): |
|
834 |
rset, vid, divid, paginate = self.filter_box_context_info() |
|
835 |
self.w(u'<div id="%s">' % divid) |
|
836 |
self.pagination(self.req, rset, w=self.w) |
|
608 | 837 |
self.wview(vid, rset, 'noresult') |
0 | 838 |
self.w(u'</div>') |
839 |
||
840 |
@cached |
|
841 |
def filter_box_context_info(self): |
|
842 |
entity = self.entity(0, 0) |
|
843 |
role, eid, rtype, etype = self.req.search_state[1] |
|
844 |
assert entity.eid == typed_eid(eid) |
|
845 |
# the default behaviour is to fetch all unrelated entities and display |
|
846 |
# them. Use fetch_order and not fetch_unrelated_order as sort method |
|
847 |
# since the latter is mainly there to select relevant items in the combo |
|
848 |
# box, it doesn't give interesting result in this context |
|
849 |
rql = entity.unrelated_rql(rtype, etype, role, |
|
850 |
ordermethod='fetch_order', |
|
851 |
vocabconstraints=False) |
|
852 |
rset = self.req.execute(rql, {'x' : entity.eid}, 'x') |
|
853 |
#vid = vid_from_rset(self.req, rset, self.schema) |
|
854 |
return rset, 'list', "search-associate-content", True |
|
855 |
||
856 |
||
857 |
class OutOfContextSearch(EntityView): |
|
858 |
id = 'outofcontext-search' |
|
859 |
def cell_call(self, row, col): |
|
860 |
entity = self.entity(row, col) |
|
861 |
erset = entity.as_rset() |
|
862 |
if linksearch_match(self.req, erset): |
|
863 |
self.w(u'<a href="%s" title="%s">%s</a> <a href="%s" title="%s">[...]</a>' % ( |
|
864 |
html_escape(linksearch_select_url(self.req, erset)), |
|
865 |
self.req._('select this entity'), |
|
866 |
html_escape(entity.view('textoutofcontext')), |
|
867 |
html_escape(entity.absolute_url(vid='primary')), |
|
868 |
self.req._('view detail for this entity'))) |
|
869 |
else: |
|
870 |
entity.view('outofcontext', w=self.w) |
|
871 |
||
872 |
||
873 |
class EditRelationView(EntityView): |
|
874 |
"""Note: This is work in progress |
|
875 |
||
876 |
This view is part of the edition view refactoring. |
|
877 |
It is still too big and cluttered with strange logic, but it's a start |
|
878 |
||
879 |
The main idea is to be able to call an edition view for a specific |
|
880 |
relation. For example : |
|
881 |
self.wview('editrelation', person_rset, rtype='firstname') |
|
882 |
self.wview('editrelation', person_rset, rtype='works_for') |
|
883 |
""" |
|
884 |
id = 'editrelation' |
|
885 |
||
431 | 886 |
__selectors__ = (match_form_params,) |
0 | 887 |
form_params = ('rtype',) |
888 |
||
889 |
# TODO: inlineview, multiple edit, (widget view ?) |
|
890 |
def cell_call(self, row, col, rtype=None, role='subject', targettype=None, |
|
891 |
showlabel=True): |
|
892 |
self.req.add_js( ('cubicweb.ajax.js', 'cubicweb.edition.js') ) |
|
893 |
entity = self.entity(row, col) |
|
894 |
rtype = self.req.form.get('rtype', rtype) |
|
895 |
showlabel = self.req.form.get('showlabel', showlabel) |
|
896 |
assert rtype is not None, "rtype is mandatory for 'edirelation' view" |
|
897 |
targettype = self.req.form.get('targettype', targettype) |
|
898 |
role = self.req.form.get('role', role) |
|
899 |
category = entity.rtags.get_category(rtype, targettype, role) |
|
570
0c9dfc430200
fix test (this view is not used actually...)
sylvain.thenault@logilab.fr
parents:
532
diff
changeset
|
900 |
if category in ('primary', 'secondary') or self.schema.rschema(rtype).is_final(): |
0 | 901 |
if hasattr(entity, '%s_format' % rtype): |
902 |
formatwdg = entity.get_widget('%s_format' % rtype, role) |
|
903 |
self.w(formatwdg.edit_render(entity)) |
|
904 |
self.w(u'<br/>') |
|
905 |
wdg = entity.get_widget(rtype, role) |
|
906 |
if showlabel: |
|
907 |
self.w(u'%s' % wdg.render_label(entity)) |
|
908 |
self.w(u'%s %s %s' % |
|
909 |
(wdg.render_error(entity), wdg.edit_render(entity), |
|
910 |
wdg.render_help(entity),)) |
|
570
0c9dfc430200
fix test (this view is not used actually...)
sylvain.thenault@logilab.fr
parents:
532
diff
changeset
|
911 |
else: |
0 | 912 |
self._render_generic_relation(entity, rtype, role) |
913 |
||
914 |
def _render_generic_relation(self, entity, relname, role): |
|
915 |
text = self.req.__('add %s %s %s' % (entity.e_schema, relname, role)) |
|
916 |
# pending operations |
|
917 |
operations = self.req.get_pending_operations(entity, relname, role) |
|
918 |
if operations['insert'] or operations['delete'] or 'unfold' in self.req.form: |
|
919 |
self.w(u'<h3>%s</h3>' % text) |
|
920 |
self._render_generic_relation_form(operations, entity, relname, role) |
|
921 |
else: |
|
922 |
divid = "%s%sreledit" % (relname, role) |
|
923 |
url = ajax_replace_url(divid, rql_for_eid(entity.eid), 'editrelation', |
|
924 |
{'unfold' : 1, 'relname' : relname, 'role' : role}) |
|
925 |
self.w(u'<a href="%s">%s</a>' % (url, text)) |
|
926 |
self.w(u'<div id="%s"></div>' % divid) |
|
927 |
||
928 |
||
929 |
def _build_opvalue(self, entity, relname, target, role): |
|
930 |
if role == 'subject': |
|
931 |
return '%s:%s:%s' % (entity.eid, relname, target) |
|
932 |
else: |
|
933 |
return '%s:%s:%s' % (target, relname, entity.eid) |
|
934 |
||
935 |
||
936 |
def _render_generic_relation_form(self, operations, entity, relname, role): |
|
937 |
rqlexec = self.req.execute |
|
938 |
for optype, targets in operations.items(): |
|
939 |
for target in targets: |
|
940 |
self._render_pending(optype, entity, relname, target, role) |
|
941 |
opvalue = self._build_opvalue(entity, relname, target, role) |
|
942 |
self.w(u'<a href="javascript: addPendingDelete(\'%s\', %s);">-</a> ' |
|
943 |
% (opvalue, entity.eid)) |
|
944 |
rset = rqlexec('Any X WHERE X eid %(x)s', {'x': target}, 'x') |
|
945 |
self.wview('oneline', rset) |
|
946 |
# now, unrelated ones |
|
947 |
self._render_unrelated_selection(entity, relname, role) |
|
948 |
||
949 |
def _render_pending(self, optype, entity, relname, target, role): |
|
950 |
opvalue = self._build_opvalue(entity, relname, target, role) |
|
951 |
self.w(u'<input type="hidden" name="__%s" value="%s" />' |
|
952 |
% (optype, opvalue)) |
|
953 |
if optype == 'insert': |
|
954 |
checktext = '-' |
|
955 |
else: |
|
956 |
checktext = '+' |
|
957 |
rset = self.req.execute('Any X WHERE X eid %(x)s', {'x': target}, 'x') |
|
958 |
self.w(u"""[<a href="javascript: cancelPending%s('%s:%s:%s')">%s</a>""" |
|
959 |
% (optype.capitalize(), relname, target, role, |
|
960 |
self.view('oneline', rset))) |
|
961 |
||
962 |
def _render_unrelated_selection(self, entity, relname, role): |
|
963 |
rschema = self.schema.rschema(relname) |
|
964 |
if role == 'subject': |
|
965 |
targettypes = rschema.objects(entity.e_schema) |
|
966 |
else: |
|
967 |
targettypes = rschema.subjects(entity.e_schema) |
|
968 |
self.w(u'<select onselect="addPendingInsert(this.selected.value);">') |
|
969 |
for targettype in targettypes: |
|
970 |
unrelated = entity.unrelated(relname, targettype, role) # XXX limit |
|
971 |
for rowindex, row in enumerate(unrelated): |
|
972 |
teid = row[0] |
|
973 |
opvalue = self._build_opvalue(entity, relname, teid, role) |
|
974 |
self.w(u'<option name="__insert" value="%s>%s</option>' |
|
975 |
% (opvalue, self.view('text', unrelated, row=rowindex))) |
|
976 |
self.w(u'</select>') |
|
977 |
||
978 |
||
979 |
class TextSearchResultView(EntityView): |
|
980 |
"""this view is used to display full-text search |
|
981 |
||
982 |
It tries to highlight part of data where the search word appears. |
|
983 |
||
984 |
XXX: finish me (fixed line width, fixed number of lines, CSS, etc.) |
|
985 |
""" |
|
986 |
id = 'tsearch' |
|
987 |
||
988 |
||
989 |
def cell_call(self, row, col, **kwargs): |
|
990 |
entity = self.complete_entity(row, col) |
|
991 |
self.w(entity.view('incontext')) |
|
992 |
searched = self.rset.searched_text() |
|
993 |
if searched is None: |
|
994 |
return |
|
995 |
searched = searched.lower() |
|
996 |
highlighted = '<b>%s</b>' % searched |
|
997 |
for attr in entity.e_schema.indexable_attributes(): |
|
998 |
try: |
|
999 |
value = html_escape(entity.printable_value(attr, format='text/plain').lower()) |
|
1000 |
except TransformError, ex: |
|
1001 |
continue |
|
1002 |
except: |
|
1003 |
continue |
|
1004 |
if searched in value: |
|
1005 |
contexts = [] |
|
1006 |
for ctx in value.split(searched): |
|
1007 |
if len(ctx) > 30: |
|
1008 |
contexts.append(u'...' + ctx[-30:]) |
|
1009 |
else: |
|
1010 |
contexts.append(ctx) |
|
1011 |
value = u'\n' + highlighted.join(contexts) |
|
1012 |
self.w(value.replace('\n', '<br/>')) |
|
1013 |
||
1014 |
||
1015 |
class EntityRelationView(EntityView): |
|
1016 |
accepts = () |
|
1017 |
vid = 'list' |
|
1018 |
||
1019 |
def cell_call(self, row, col): |
|
1020 |
if self.target == 'object': |
|
1021 |
role = 'subject' |
|
1022 |
else: |
|
1023 |
role = 'object' |
|
1024 |
rset = self.rset.get_entity(row, col).related(self.rtype, role) |
|
956 | 1025 |
if self.title: |
1026 |
self.w(u'<h1>%s</h1>' % self.req._(self.title).capitalize()) |
|
0 | 1027 |
self.w(u'<div class="mainInfo">') |
1028 |
self.wview(self.vid, rset, 'noresult') |
|
1029 |
self.w(u'</div>') |
|
1030 |
||
1031 |
||
1032 |
class TooltipView(OneLineView): |
|
1033 |
"""A entity view used in a tooltip""" |
|
1034 |
id = 'tooltip' |
|
1035 |
title = None # don't display in possible views |
|
1036 |
def cell_call(self, row, col): |
|
1037 |
self.wview('oneline', self.rset, row=row, col=col) |
|
1038 |
||
1039 |
try: |
|
1040 |
from cubicweb.web.views.tableview import TableView |
|
1041 |
from logilab.common.deprecation import class_moved |
|
1042 |
TableView = class_moved(TableView) |
|
1043 |
except ImportError: |
|
1044 |
pass # gae has no tableview module (yet) |