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