author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 24 Jul 2009 12:10:54 +0200 | |
changeset 2470 | 569d6641f08c |
parent 2469 | b87c4d150e09 |
child 2471 | 3e2b50ece726 |
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 |
||
8 |
||
9 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1882
diff
changeset
|
10 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 11 |
: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:
1882
diff
changeset
|
12 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 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 |
0 | 15 |
__docformat__ = "restructuredtext en" |
1882 | 16 |
_ = unicode |
0 | 17 |
|
18 |
from rql import nodes |
|
19 |
||
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
20 |
from logilab.mtconverter import TransformError, xml_escape, xml_escape |
0 | 21 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
22 |
from cubicweb import NoSelectableObject |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
23 |
from cubicweb.selectors import yes, empty_rset |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
24 |
from cubicweb.schema import display_name |
756 | 25 |
from cubicweb.view import EntityView, AnyRsetView, View |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
26 |
from cubicweb.common.uilib import cut, printable_value |
0 | 27 |
|
28 |
||
29 |
class NullView(AnyRsetView): |
|
30 |
"""default view when no result has been found""" |
|
31 |
id = 'null' |
|
758
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
32 |
__select__ = yes() |
0 | 33 |
def call(self, **kwargs): |
34 |
pass |
|
35 |
cell_call = call |
|
36 |
||
37 |
||
632 | 38 |
class NoResultView(View): |
0 | 39 |
"""default view when no result has been found""" |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
647
diff
changeset
|
40 |
__select__ = empty_rset() |
0 | 41 |
id = 'noresult' |
1451 | 42 |
|
0 | 43 |
def call(self, **kwargs): |
44 |
self.w(u'<div class="searchMessage"><strong>%s</strong></div>\n' |
|
45 |
% self.req._('No result matching query')) |
|
46 |
||
47 |
||
48 |
class FinalView(AnyRsetView): |
|
49 |
"""display values without any transformation (i.e. get a number for |
|
1451 | 50 |
entities) |
0 | 51 |
""" |
52 |
id = 'final' |
|
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
53 |
# record generated i18n catalog messages |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
54 |
_('%d years') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
55 |
_('%d months') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
56 |
_('%d weeks') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
57 |
_('%d days') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
58 |
_('%d hours') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
59 |
_('%d minutes') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
60 |
_('%d seconds') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
61 |
_('%d years') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
62 |
_('%d months') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
63 |
_('%d weeks') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
64 |
_('%d days') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
65 |
_('%d hours') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
66 |
_('%d minutes') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
67 |
_('%d seconds') |
1451 | 68 |
|
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
69 |
def cell_call(self, row, col, props=None, displaytime=False, format='text/html'): |
0 | 70 |
etype = self.rset.description[row][col] |
71 |
value = self.rset.rows[row][col] |
|
1760
6b97d286eb5a
[reledit] relation edition : cleanup a bit #343123
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1712
diff
changeset
|
72 |
|
0 | 73 |
if etype == 'String': |
74 |
entity, rtype = self.rset.related_entity(row, col) |
|
75 |
if entity is not None: |
|
76 |
# yes ! |
|
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
77 |
self.w(entity.printable_value(rtype, value, format=format)) |
0 | 78 |
return |
79 |
if etype in ('Time', 'Interval'): |
|
1451 | 80 |
# value is DateTimeDelta but we have no idea about what is the |
0 | 81 |
# 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
|
82 |
if format == 'text/html': |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
83 |
space = ' ' |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
84 |
else: |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
85 |
space = ' ' |
0 | 86 |
if value.days > 730: # 2 years |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
87 |
self.w(self.req.__('%%d%syears' % space) % (value.days // 365)) |
0 | 88 |
elif value.days > 60: # 2 months |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
89 |
self.w(self.req.__('%%d%smonths' % space) % (value.days // 30)) |
0 | 90 |
elif value.days > 14: # 2 weeks |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
91 |
self.w(self.req.__('%%d%sweeks' % space) % (value.days // 7)) |
0 | 92 |
elif value.days > 2: |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
93 |
self.w(self.req.__('%%d%sdays' % space) % int(value.days)) |
1712
32ab85031814
fix a bug deltatime hasn't a hours or minutes attributes
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1680
diff
changeset
|
94 |
elif value.seconds > 3600: |
32ab85031814
fix a bug deltatime hasn't a hours or minutes attributes
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1680
diff
changeset
|
95 |
self.w(self.req.__('%%d%shours' % space) % int(value.seconds // 3600)) |
32ab85031814
fix a bug deltatime hasn't a hours or minutes attributes
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1680
diff
changeset
|
96 |
elif value.seconds >= 120: |
32ab85031814
fix a bug deltatime hasn't a hours or minutes attributes
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1680
diff
changeset
|
97 |
self.w(self.req.__('%%d%sminutes' % space) % int(value.seconds // 60)) |
0 | 98 |
else: |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
99 |
self.w(self.req.__('%%d%sseconds' % space) % int(value.seconds)) |
0 | 100 |
return |
101 |
self.wdata(printable_value(self.req, etype, value, props, displaytime=displaytime)) |
|
102 |
||
103 |
||
104 |
class SecondaryView(EntityView): |
|
105 |
id = 'secondary' |
|
106 |
title = _('secondary') |
|
1451 | 107 |
|
0 | 108 |
def cell_call(self, row, col): |
109 |
"""the secondary view for an entity |
|
110 |
secondary = icon + view(oneline) |
|
111 |
""" |
|
112 |
entity = self.entity(row, col) |
|
113 |
self.w(u' ') |
|
114 |
self.wview('oneline', self.rset, row=row, col=col) |
|
115 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
116 |
|
0 | 117 |
class OneLineView(EntityView): |
118 |
id = 'oneline' |
|
1451 | 119 |
title = _('oneline') |
0 | 120 |
|
121 |
def cell_call(self, row, col): |
|
122 |
"""the one line view for an entity: linked text view |
|
123 |
""" |
|
124 |
entity = self.entity(row, col) |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
125 |
self.w(u'<a href="%s">' % xml_escape(entity.absolute_url())) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
126 |
self.w(xml_escape(self.view('text', self.rset, row=row, col=col))) |
0 | 127 |
self.w(u'</a>') |
128 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
129 |
|
0 | 130 |
class TextView(EntityView): |
532
ce3e94cbb074
specify content type for text views
sylvain.thenault@logilab.fr
parents:
531
diff
changeset
|
131 |
"""the simplest text view for an entity""" |
0 | 132 |
id = 'text' |
133 |
title = _('text') |
|
532
ce3e94cbb074
specify content type for text views
sylvain.thenault@logilab.fr
parents:
531
diff
changeset
|
134 |
content_type = 'text/plain' |
647
49bb57a9606b
some selectors update + drop EntityRelationView (only used by jpl)
sylvain.thenault@logilab.fr
parents:
632
diff
changeset
|
135 |
|
0 | 136 |
def call(self, **kwargs): |
137 |
"""the view is called for an entire result set, by default loop |
|
138 |
other rows of the result set and call the same view on the |
|
139 |
particular row |
|
140 |
||
141 |
Views applicable on None result sets have to override this method |
|
142 |
""" |
|
143 |
rset = self.rset |
|
144 |
if rset is None: |
|
145 |
raise NotImplementedError, self |
|
146 |
for i in xrange(len(rset)): |
|
147 |
self.wview(self.id, rset, row=i, **kwargs) |
|
148 |
if len(rset) > 1: |
|
149 |
self.w(u"\n") |
|
1451 | 150 |
|
0 | 151 |
def cell_call(self, row, col=0, **kwargs): |
152 |
entity = self.entity(row, col) |
|
153 |
self.w(cut(entity.dc_title(), |
|
154 |
self.req.property_value('navigation.short-line-size'))) |
|
155 |
||
137
7e45cf48c2f1
don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
156 |
|
0 | 157 |
class MetaDataView(EntityView): |
158 |
"""paragraph view of some metadata""" |
|
159 |
id = 'metadata' |
|
160 |
show_eid = True |
|
1451 | 161 |
|
0 | 162 |
def cell_call(self, row, col): |
163 |
_ = self.req._ |
|
164 |
entity = self.entity(row, col) |
|
165 |
self.w(u'<div class="metadata">') |
|
166 |
if self.show_eid: |
|
167 |
self.w(u'#%s - ' % entity.eid) |
|
168 |
if entity.modification_date != entity.creation_date: |
|
169 |
self.w(u'<span>%s</span> ' % _('latest update on')) |
|
1552 | 170 |
self.w(u'<span class="value">%s</span>, ' |
0 | 171 |
% self.format_date(entity.modification_date)) |
172 |
# entities from external source may not have a creation date (eg ldap) |
|
1451 | 173 |
if entity.creation_date: |
0 | 174 |
self.w(u'<span>%s</span> ' % _('created on')) |
175 |
self.w(u'<span class="value">%s</span>' |
|
176 |
% self.format_date(entity.creation_date)) |
|
177 |
if entity.creator: |
|
1456
998ff29c3390
related entitied must be computed in _preinit_side_related
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1431
diff
changeset
|
178 |
self.w(u' <span>%s</span> ' % _('by')) |
0 | 179 |
self.w(u'<span class="value">%s</span>' % entity.creator.name()) |
180 |
self.w(u'</div>') |
|
181 |
||
182 |
||
183 |
# new default views for finner control in general views , to use instead of |
|
184 |
# oneline / secondary |
|
185 |
||
186 |
class InContextTextView(TextView): |
|
187 |
id = 'textincontext' |
|
188 |
title = None # not listed as a possible view |
|
189 |
def cell_call(self, row, col): |
|
190 |
entity = self.entity(row, col) |
|
191 |
self.w(entity.dc_title()) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
192 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
193 |
|
0 | 194 |
class OutOfContextTextView(InContextTextView): |
195 |
id = 'textoutofcontext' |
|
196 |
||
197 |
def cell_call(self, row, col): |
|
198 |
entity = self.entity(row, col) |
|
199 |
self.w(entity.dc_long_title()) |
|
200 |
||
201 |
||
202 |
class InContextView(EntityView): |
|
203 |
id = 'incontext' |
|
204 |
||
205 |
def cell_call(self, row, col): |
|
206 |
entity = self.entity(row, col) |
|
207 |
desc = cut(entity.dc_description(), 50) |
|
1882 | 208 |
self.w(u'<a href="%s" title="%s">' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
209 |
xml_escape(entity.absolute_url()), xml_escape(desc))) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
210 |
self.w(xml_escape(self.view('textincontext', self.rset, |
1882 | 211 |
row=row, col=col))) |
0 | 212 |
self.w(u'</a>') |
213 |
||
1451 | 214 |
|
0 | 215 |
class OutOfContextView(EntityView): |
216 |
id = 'outofcontext' |
|
217 |
||
218 |
def cell_call(self, row, col): |
|
1882 | 219 |
entity = self.entity(row, col) |
220 |
desc = cut(entity.dc_description(), 50) |
|
221 |
self.w(u'<a href="%s" title="%s">' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
222 |
xml_escape(entity.absolute_url()), xml_escape(desc))) |
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
223 |
self.w(xml_escape(self.view('textoutofcontext', self.rset, |
1882 | 224 |
row=row, col=col))) |
0 | 225 |
self.w(u'</a>') |
226 |
||
227 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
228 |
# list views ################################################################## |
0 | 229 |
|
230 |
class ListView(EntityView): |
|
231 |
id = 'list' |
|
232 |
title = _('list') |
|
233 |
item_vid = 'listitem' |
|
1451 | 234 |
|
0 | 235 |
def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs): |
236 |
"""display a list of entities by calling their <item_vid> view |
|
1451 | 237 |
|
0 | 238 |
:param listid: the DOM id to use for the root element |
239 |
""" |
|
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
240 |
# XXX much of the behaviour here should probably be outside this view |
0 | 241 |
if subvid is None and 'subvid' in self.req.form: |
242 |
subvid = self.req.form.pop('subvid') # consume it |
|
243 |
if listid: |
|
244 |
listid = u' id="%s"' % listid |
|
245 |
else: |
|
246 |
listid = u'' |
|
247 |
if title: |
|
248 |
self.w(u'<div%s class="%s"><h4>%s</h4>\n' % (listid, klass or 'section', title)) |
|
249 |
self.w(u'<ul>\n') |
|
250 |
else: |
|
251 |
self.w(u'<ul%s class="%s">\n' % (listid, klass or 'section')) |
|
252 |
for i in xrange(self.rset.rowcount): |
|
253 |
self.cell_call(row=i, col=0, vid=subvid, **kwargs) |
|
254 |
self.w(u'</ul>\n') |
|
255 |
if title: |
|
256 |
self.w(u'</div>\n') |
|
257 |
||
258 |
def cell_call(self, row, col=0, vid=None, **kwargs): |
|
259 |
self.w(u'<li>') |
|
260 |
self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs) |
|
261 |
self.w(u'</li>\n') |
|
262 |
||
1451 | 263 |
|
0 | 264 |
class ListItemView(EntityView): |
265 |
id = 'listitem' |
|
1451 | 266 |
|
0 | 267 |
@property |
268 |
def redirect_vid(self): |
|
269 |
if self.req.search_state[0] == 'normal': |
|
270 |
return 'outofcontext' |
|
271 |
return 'outofcontext-search' |
|
1451 | 272 |
|
0 | 273 |
def cell_call(self, row, col, vid=None, **kwargs): |
274 |
if not vid: |
|
275 |
vid = self.redirect_vid |
|
276 |
try: |
|
277 |
self.wview(vid, self.rset, row=row, col=col, **kwargs) |
|
278 |
except NoSelectableObject: |
|
279 |
if vid == self.redirect_vid: |
|
280 |
raise |
|
281 |
self.wview(self.redirect_vid, self.rset, row=row, col=col, **kwargs) |
|
282 |
||
283 |
||
284 |
class SimpleListView(ListItemView): |
|
285 |
"""list without bullets""" |
|
286 |
id = 'simplelist' |
|
287 |
redirect_vid = 'incontext' |
|
288 |
||
289 |
||
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
290 |
class AdaptedListView(ListItemView): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
291 |
"""list of entities of the same type""" |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
292 |
id = 'adaptedlist' |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
293 |
__select__ = non_final_entity() & one_etype_rset() |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
294 |
item_vid = 'adaptedlistitem' |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
295 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
296 |
@property |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
297 |
def title(self): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
298 |
etype = iter(self.rset.column_types(0)).next() |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
299 |
return display_name(self.req, etype, form='plural')) |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
300 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
301 |
def call(self, **kwargs): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
302 |
"""display a list of entities by calling their <item_vid> view""" |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
303 |
if not 'vtitle' in self.req.form: |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
304 |
self.w(u'<h1>%s</h1>' % self.title) |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
305 |
super(AdaptedListView, self).call(**kwargs) |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
306 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
307 |
def cell_call(self, row, col=0, vid=None, **kwargs): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
308 |
self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs) |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
309 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
310 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
311 |
class AdaptedListItemView(ListItemView): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
312 |
id = 'adaptedlistitem' |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
313 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
314 |
|
0 | 315 |
class CSVView(SimpleListView): |
316 |
id = 'csv' |
|
317 |
redirect_vid = 'incontext' |
|
1451 | 318 |
|
0 | 319 |
def call(self, **kwargs): |
320 |
rset = self.rset |
|
321 |
for i in xrange(len(rset)): |
|
322 |
self.cell_call(i, 0, vid=kwargs.get('vid')) |
|
323 |
if i < rset.rowcount-1: |
|
324 |
self.w(u", ") |
|
325 |
||
326 |
||
327 |
class TreeItemView(ListItemView): |
|
328 |
id = 'treeitem' |
|
329 |
||
330 |
def cell_call(self, row, col): |
|
331 |
self.wview('incontext', self.rset, row=row, col=col) |
|
332 |
||
333 |
class TextSearchResultView(EntityView): |
|
334 |
"""this view is used to display full-text search |
|
335 |
||
336 |
It tries to highlight part of data where the search word appears. |
|
337 |
||
338 |
XXX: finish me (fixed line width, fixed number of lines, CSS, etc.) |
|
339 |
""" |
|
340 |
id = 'tsearch' |
|
341 |
||
342 |
def cell_call(self, row, col, **kwargs): |
|
343 |
entity = self.complete_entity(row, col) |
|
344 |
self.w(entity.view('incontext')) |
|
345 |
searched = self.rset.searched_text() |
|
346 |
if searched is None: |
|
347 |
return |
|
348 |
searched = searched.lower() |
|
349 |
highlighted = '<b>%s</b>' % searched |
|
350 |
for attr in entity.e_schema.indexable_attributes(): |
|
351 |
try: |
|
1680
39860636e184
use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1653
diff
changeset
|
352 |
value = xml_escape(entity.printable_value(attr, format='text/plain').lower()) |
0 | 353 |
except TransformError, ex: |
354 |
continue |
|
355 |
except: |
|
356 |
continue |
|
357 |
if searched in value: |
|
358 |
contexts = [] |
|
359 |
for ctx in value.split(searched): |
|
360 |
if len(ctx) > 30: |
|
361 |
contexts.append(u'...' + ctx[-30:]) |
|
362 |
else: |
|
363 |
contexts.append(ctx) |
|
364 |
value = u'\n' + highlighted.join(contexts) |
|
1451 | 365 |
self.w(value.replace('\n', '<br/>')) |
0 | 366 |
|
367 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
368 |
class TooltipView(EntityView): |
0 | 369 |
"""A entity view used in a tooltip""" |
370 |
id = 'tooltip' |
|
371 |
def cell_call(self, row, col): |
|
372 |
self.wview('oneline', self.rset, row=row, col=col) |
|
373 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
374 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
375 |
# XXX bw compat |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
376 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
377 |
from logilab.common.deprecation import class_moved |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
378 |
|
0 | 379 |
try: |
380 |
from cubicweb.web.views.tableview import TableView |
|
381 |
TableView = class_moved(TableView) |
|
382 |
except ImportError: |
|
383 |
pass # gae has no tableview module (yet) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
384 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
385 |
from cubicweb.web.views import boxes, xmlrss, primary |
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
386 |
PrimaryView = class_moved(primary.PrimaryView) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
387 |
SideBoxView = class_moved(boxes.SideBoxView) |
1653 | 388 |
XmlView = class_moved(xmlrss.XMLView) |
389 |
XmlItemView = class_moved(xmlrss.XMLItemView) |
|
390 |
XmlRsetView = class_moved(xmlrss.XMLRsetView) |
|
391 |
RssView = class_moved(xmlrss.RSSView) |
|
392 |
RssItemView = class_moved(xmlrss.RSSItemView) |
|
1451 | 393 |