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