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