author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Wed, 16 Dec 2009 14:19:01 +0100 | |
branch | stable |
changeset 4256 | bf6e0e75acfa |
parent 4212 | ab6573088b4a |
child 4252 | 6c4f109c2b03 |
child 4315 | 2f957ad8e082 |
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 |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3843
diff
changeset
|
10 |
:copyright: 2001-2010 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 |
|
3682
9b62c5887639
add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3264
diff
changeset
|
118 |
def cell_call(self, row, col, **kwargs): |
0 | 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 |
|
3682
9b62c5887639
add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3264
diff
changeset
|
131 |
def cell_call(self, row, col, **kwargs): |
0 | 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: |
|
3843
200719b9221f
display entity type in metadata section instead of default title of primary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3794
diff
changeset
|
177 |
self.w(u'%s #%s - ' % (entity.dc_type(), entity.eid)) |
0 | 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 |
||
3682
9b62c5887639
add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3264
diff
changeset
|
225 |
def cell_call(self, row, col, **kwargs): |
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'' |
|
3794
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
254 |
if self.rset.rowcount: |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
255 |
if title: |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
256 |
self.w(u'<div%s class="%s"><h4>%s</h4>\n' % (listid, klass or 'section', title)) |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
257 |
self.w(u'<ul>\n') |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
258 |
else: |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
259 |
self.w(u'<ul%s class="%s">\n' % (listid, klass or 'section')) |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
260 |
for i in xrange(self.rset.rowcount): |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
261 |
self.cell_call(row=i, col=0, vid=subvid, **kwargs) |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
262 |
self.w(u'</ul>\n') |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
263 |
if title: |
c741061d5348
[B] views: fix wrong xhtml when empty rset
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
3682
diff
changeset
|
264 |
self.w(u'</div>\n') |
0 | 265 |
|
266 |
def cell_call(self, row, col=0, vid=None, **kwargs): |
|
267 |
self.w(u'<li>') |
|
268 |
self.wview(self.item_vid, self.rset, row=row, col=col, vid=vid, **kwargs) |
|
269 |
self.w(u'</li>\n') |
|
270 |
||
1451 | 271 |
|
0 | 272 |
class ListItemView(EntityView): |
273 |
id = 'listitem' |
|
1451 | 274 |
|
0 | 275 |
@property |
276 |
def redirect_vid(self): |
|
277 |
if self.req.search_state[0] == 'normal': |
|
278 |
return 'outofcontext' |
|
279 |
return 'outofcontext-search' |
|
1451 | 280 |
|
0 | 281 |
def cell_call(self, row, col, vid=None, **kwargs): |
282 |
if not vid: |
|
283 |
vid = self.redirect_vid |
|
284 |
try: |
|
285 |
self.wview(vid, self.rset, row=row, col=col, **kwargs) |
|
286 |
except NoSelectableObject: |
|
287 |
if vid == self.redirect_vid: |
|
288 |
raise |
|
289 |
self.wview(self.redirect_vid, self.rset, row=row, col=col, **kwargs) |
|
290 |
||
291 |
||
292 |
class SimpleListView(ListItemView): |
|
293 |
"""list without bullets""" |
|
294 |
id = 'simplelist' |
|
295 |
redirect_vid = 'incontext' |
|
296 |
||
297 |
||
2472
a459a6ab78d0
fix syntax/import errors & adapted list base class
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2471
diff
changeset
|
298 |
class AdaptedListView(EntityView): |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
299 |
"""list of entities of the same type""" |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
300 |
id = 'adaptedlist' |
2645
91c71276f999
F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2472
diff
changeset
|
301 |
__select__ = EntityView.__select__ & one_etype_rset() |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
302 |
item_vid = 'adaptedlistitem' |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
303 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
304 |
@property |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
305 |
def title(self): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
306 |
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
|
307 |
return display_name(self.req, etype, form='plural') |
2469
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 |
def call(self, **kwargs): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
310 |
"""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
|
311 |
if not 'vtitle' in self.req.form: |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
312 |
self.w(u'<h1>%s</h1>' % self.title) |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
313 |
super(AdaptedListView, self).call(**kwargs) |
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 |
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
|
316 |
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
|
317 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
318 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
319 |
class AdaptedListItemView(ListItemView): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
320 |
id = 'adaptedlistitem' |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
321 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
322 |
|
0 | 323 |
class CSVView(SimpleListView): |
324 |
id = 'csv' |
|
325 |
redirect_vid = 'incontext' |
|
1451 | 326 |
|
0 | 327 |
def call(self, **kwargs): |
328 |
rset = self.rset |
|
329 |
for i in xrange(len(rset)): |
|
330 |
self.cell_call(i, 0, vid=kwargs.get('vid')) |
|
331 |
if i < rset.rowcount-1: |
|
332 |
self.w(u", ") |
|
333 |
||
334 |
||
335 |
class TreeItemView(ListItemView): |
|
336 |
id = 'treeitem' |
|
337 |
||
338 |
def cell_call(self, row, col): |
|
339 |
self.wview('incontext', self.rset, row=row, col=col) |
|
340 |
||
341 |
class TextSearchResultView(EntityView): |
|
342 |
"""this view is used to display full-text search |
|
343 |
||
344 |
It tries to highlight part of data where the search word appears. |
|
345 |
||
346 |
XXX: finish me (fixed line width, fixed number of lines, CSS, etc.) |
|
347 |
""" |
|
348 |
id = 'tsearch' |
|
349 |
||
350 |
def cell_call(self, row, col, **kwargs): |
|
351 |
entity = self.complete_entity(row, col) |
|
352 |
self.w(entity.view('incontext')) |
|
353 |
searched = self.rset.searched_text() |
|
354 |
if searched is None: |
|
355 |
return |
|
356 |
searched = searched.lower() |
|
357 |
highlighted = '<b>%s</b>' % searched |
|
358 |
for attr in entity.e_schema.indexable_attributes(): |
|
359 |
try: |
|
1680
39860636e184
use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1653
diff
changeset
|
360 |
value = xml_escape(entity.printable_value(attr, format='text/plain').lower()) |
0 | 361 |
except TransformError, ex: |
362 |
continue |
|
363 |
except: |
|
364 |
continue |
|
365 |
if searched in value: |
|
366 |
contexts = [] |
|
367 |
for ctx in value.split(searched): |
|
368 |
if len(ctx) > 30: |
|
369 |
contexts.append(u'...' + ctx[-30:]) |
|
370 |
else: |
|
371 |
contexts.append(ctx) |
|
372 |
value = u'\n' + highlighted.join(contexts) |
|
1451 | 373 |
self.w(value.replace('\n', '<br/>')) |
0 | 374 |
|
375 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
376 |
class TooltipView(EntityView): |
0 | 377 |
"""A entity view used in a tooltip""" |
378 |
id = 'tooltip' |
|
379 |
def cell_call(self, row, col): |
|
380 |
self.wview('oneline', self.rset, row=row, col=col) |
|
381 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
382 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
383 |
# XXX bw compat |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
384 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
385 |
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
|
386 |
|
0 | 387 |
try: |
388 |
from cubicweb.web.views.tableview import TableView |
|
389 |
TableView = class_moved(TableView) |
|
390 |
except ImportError: |
|
391 |
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
|
392 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
393 |
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
|
394 |
PrimaryView = class_moved(primary.PrimaryView) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
395 |
SideBoxView = class_moved(boxes.SideBoxView) |
1653 | 396 |
XmlView = class_moved(xmlrss.XMLView) |
397 |
XmlItemView = class_moved(xmlrss.XMLItemView) |
|
398 |
XmlRsetView = class_moved(xmlrss.XMLRsetView) |
|
399 |
RssView = class_moved(xmlrss.RSSView) |
|
400 |
RssItemView = class_moved(xmlrss.RSSItemView) |
|
1451 | 401 |