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