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