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