author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 11 Jan 2011 12:19:36 +0100 | |
branch | stable |
changeset 6800 | 3f3d576b87d9 |
parent 6740 | e4974d5f7dca |
child 6883 | 1538542a88ed |
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 |
|
6455
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
36 |
from cubicweb import NoSelectableObject, tags |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
37 |
from cubicweb.selectors import yes, empty_rset, one_etype_rset, match_kwargs |
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 |
6455
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
41 |
from cubicweb.web.views import calendar |
0 | 42 |
|
43 |
||
44 |
class NullView(AnyRsetView): |
|
45 |
"""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
|
46 |
__regid__ = 'null' |
758
0c0dfd33a76d
instantiate selectors wherever needed
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
47 |
__select__ = yes() |
0 | 48 |
def call(self, **kwargs): |
49 |
pass |
|
50 |
cell_call = call |
|
51 |
||
52 |
||
632 | 53 |
class NoResultView(View): |
0 | 54 |
"""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
|
55 |
__select__ = empty_rset() |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
56 |
__regid__ = 'noresult' |
1451 | 57 |
|
0 | 58 |
def call(self, **kwargs): |
59 |
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
|
60 |
% self._cw._('No result matching query')) |
0 | 61 |
|
62 |
||
63 |
class FinalView(AnyRsetView): |
|
64 |
"""display values without any transformation (i.e. get a number for |
|
1451 | 65 |
entities) |
0 | 66 |
""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
67 |
__regid__ = 'final' |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
68 |
# 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
|
69 |
_('%d years') |
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
70 |
_('%d months') |
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
71 |
_('%d weeks') |
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
72 |
_('%d days') |
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
73 |
_('%d hours') |
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
74 |
_('%d minutes') |
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
75 |
_('%d seconds') |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
76 |
_('%d years') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
77 |
_('%d months') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
78 |
_('%d weeks') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
79 |
_('%d days') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
80 |
_('%d hours') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
81 |
_('%d minutes') |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
82 |
_('%d seconds') |
1451 | 83 |
|
3165
0a50ebe53db7
[views] remove parameter displaytime from final view
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
2996
diff
changeset
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
|
4315
2f957ad8e082
[views] FinalView should display an empty string if value is None
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4212
diff
changeset
|
88 |
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
|
89 |
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
|
90 |
return |
0 | 91 |
if etype == 'String': |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
92 |
entity, rtype = self.cw_rset.related_entity(row, col) |
0 | 93 |
if entity is not None: |
94 |
# yes ! |
|
573
9c8fd72ba6c1
try to get raw text values in rset csv view
sylvain.thenault@logilab.fr
parents:
570
diff
changeset
|
95 |
self.w(entity.printable_value(rtype, value, format=format)) |
0 | 96 |
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
|
97 |
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
|
98 |
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
|
99 |
# `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
|
100 |
# (number of days), not a timedelta |
3236 | 101 |
# XXX should rql be fixed to return Int instead of Interval in |
102 |
# that case? that would be probably the proper fix but we |
|
103 |
# 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
|
104 |
value = timedelta(days=value) |
1451 | 105 |
# value is DateTimeDelta but we have no idea about what is the |
0 | 106 |
# 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
|
107 |
if format == 'text/html': |
2996
866a2c135c33
B #345282 xhtml requires to use   instead of
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2645
diff
changeset
|
108 |
space = ' ' |
978
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
109 |
else: |
536c748e7b3f
use non-breakable space in time display
sylvain.thenault@logilab.fr
parents:
964
diff
changeset
|
110 |
space = ' ' |
0 | 111 |
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
|
112 |
self.w(self._cw.__('%%d%syears' % space) % (value.days // 365)) |
0 | 113 |
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
|
114 |
self.w(self._cw.__('%%d%smonths' % space) % (value.days // 30)) |
0 | 115 |
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
|
116 |
self.w(self._cw.__('%%d%sweeks' % space) % (value.days // 7)) |
0 | 117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
self.w(self._cw.__('%%d%sminutes' % space) % int(value.seconds // 60)) |
0 | 123 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
124 |
self.w(self._cw.__('%%d%sseconds' % space) % int(value.seconds)) |
0 | 125 |
return |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
126 |
self.wdata(printable_value(self._cw, etype, value, props)) |
0 | 127 |
|
128 |
||
2471
3e2b50ece726
begin to drop ref to secondary view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2469
diff
changeset
|
129 |
# XXX deprecated |
0 | 130 |
class SecondaryView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
131 |
__regid__ = 'secondary' |
0 | 132 |
title = _('secondary') |
1451 | 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 secondary view for an entity |
136 |
secondary = icon + view(oneline) |
|
137 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
138 |
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
|
139 |
self.w(u' ') |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
140 |
self.wview('oneline', self.cw_rset, row=row, col=col) |
0 | 141 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
142 |
|
0 | 143 |
class OneLineView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
144 |
__regid__ = 'oneline' |
1451 | 145 |
title = _('oneline') |
0 | 146 |
|
3682
9b62c5887639
add kwargs to some base views
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3264
diff
changeset
|
147 |
def cell_call(self, row, col, **kwargs): |
0 | 148 |
"""the one line view for an entity: linked text view |
149 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
150 |
entity = self.cw_rset.get_entity(row, col) |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
151 |
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
|
152 |
self.w(xml_escape(self._cw.view('text', self.cw_rset, row=row, col=col))) |
0 | 153 |
self.w(u'</a>') |
154 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
155 |
|
0 | 156 |
class TextView(EntityView): |
532
ce3e94cbb074
specify content type for text views
sylvain.thenault@logilab.fr
parents:
531
diff
changeset
|
157 |
"""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
|
158 |
__regid__ = 'text' |
0 | 159 |
title = _('text') |
532
ce3e94cbb074
specify content type for text views
sylvain.thenault@logilab.fr
parents:
531
diff
changeset
|
160 |
content_type = 'text/plain' |
647
49bb57a9606b
some selectors update + drop EntityRelationView (only used by jpl)
sylvain.thenault@logilab.fr
parents:
632
diff
changeset
|
161 |
|
0 | 162 |
def call(self, **kwargs): |
163 |
"""the view is called for an entire result set, by default loop |
|
164 |
other rows of the result set and call the same view on the |
|
165 |
particular row |
|
166 |
||
167 |
Views applicable on None result sets have to override this method |
|
168 |
""" |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
169 |
rset = self.cw_rset |
0 | 170 |
if rset is None: |
171 |
raise NotImplementedError, self |
|
172 |
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
|
173 |
self.wview(self.__regid__, rset, row=i, **kwargs) |
0 | 174 |
if len(rset) > 1: |
175 |
self.w(u"\n") |
|
1451 | 176 |
|
0 | 177 |
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
|
178 |
entity = self.cw_rset.get_entity(row, col) |
0 | 179 |
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
|
180 |
self._cw.property_value('navigation.short-line-size'))) |
0 | 181 |
|
137
7e45cf48c2f1
don't display additional owners in metadata, this is confusing
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
182 |
|
0 | 183 |
class MetaDataView(EntityView): |
184 |
"""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
|
185 |
__regid__ = 'metadata' |
0 | 186 |
show_eid = True |
1451 | 187 |
|
0 | 188 |
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
|
189 |
_ = self._cw._ |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
190 |
entity = self.cw_rset.get_entity(row, col) |
6740
e4974d5f7dca
remove "metadata" class from MetaDataView as it is now set by SectionLayout (view.cssclass)
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
6583
diff
changeset
|
191 |
self.w(u'<div>') |
0 | 192 |
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
|
193 |
self.w(u'%s #%s - ' % (entity.dc_type(), entity.eid)) |
0 | 194 |
if entity.modification_date != entity.creation_date: |
195 |
self.w(u'<span>%s</span> ' % _('latest update on')) |
|
1552 | 196 |
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
|
197 |
% self._cw.format_date(entity.modification_date)) |
0 | 198 |
# entities from external source may not have a creation date (eg ldap) |
1451 | 199 |
if entity.creation_date: |
0 | 200 |
self.w(u'<span>%s</span> ' % _('created on')) |
201 |
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
|
202 |
% self._cw.format_date(entity.creation_date)) |
0 | 203 |
if entity.creator: |
1456
998ff29c3390
related entitied must be computed in _preinit_side_related
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1431
diff
changeset
|
204 |
self.w(u' <span>%s</span> ' % _('by')) |
0 | 205 |
self.w(u'<span class="value">%s</span>' % entity.creator.name()) |
206 |
self.w(u'</div>') |
|
207 |
||
208 |
||
209 |
class InContextTextView(TextView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
210 |
__regid__ = 'textincontext' |
0 | 211 |
title = None # not listed as a possible view |
212 |
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
|
213 |
entity = self.cw_rset.get_entity(row, col) |
0 | 214 |
self.w(entity.dc_title()) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
215 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
216 |
|
0 | 217 |
class OutOfContextTextView(InContextTextView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
218 |
__regid__ = 'textoutofcontext' |
0 | 219 |
|
220 |
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
|
221 |
entity = self.cw_rset.get_entity(row, col) |
0 | 222 |
self.w(entity.dc_long_title()) |
223 |
||
224 |
||
225 |
class InContextView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
226 |
__regid__ = 'incontext' |
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) |
0 | 230 |
desc = cut(entity.dc_description(), 50) |
1882 | 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('textincontext', 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 |
||
1451 | 237 |
|
0 | 238 |
class OutOfContextView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
239 |
__regid__ = 'outofcontext' |
0 | 240 |
|
241 |
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
|
242 |
entity = self.cw_rset.get_entity(row, col) |
1882 | 243 |
desc = cut(entity.dc_description(), 50) |
244 |
self.w(u'<a href="%s" title="%s">' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
245 |
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
|
246 |
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
|
247 |
row=row, col=col))) |
0 | 248 |
self.w(u'</a>') |
249 |
||
250 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
251 |
# list views ################################################################## |
0 | 252 |
|
253 |
class ListView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
254 |
__regid__ = 'list' |
0 | 255 |
title = _('list') |
256 |
item_vid = 'listitem' |
|
1451 | 257 |
|
0 | 258 |
def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs): |
259 |
"""display a list of entities by calling their <item_vid> view |
|
1451 | 260 |
|
0 | 261 |
:param listid: the DOM id to use for the root element |
262 |
""" |
|
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
263 |
# 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
|
264 |
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
|
265 |
subvid = self._cw.form.pop('subvid') # consume it |
0 | 266 |
if listid: |
267 |
listid = u' id="%s"' % listid |
|
268 |
else: |
|
269 |
listid = u'' |
|
270 |
if title: |
|
271 |
self.w(u'<div%s class="%s"><h4>%s</h4>\n' % (listid, klass or 'section', title)) |
|
272 |
self.w(u'<ul>\n') |
|
273 |
else: |
|
274 |
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
|
275 |
for i in xrange(self.cw_rset.rowcount): |
0 | 276 |
self.cell_call(row=i, col=0, vid=subvid, **kwargs) |
277 |
self.w(u'</ul>\n') |
|
278 |
if title: |
|
279 |
self.w(u'</div>\n') |
|
280 |
||
281 |
def cell_call(self, row, col=0, vid=None, **kwargs): |
|
282 |
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
|
283 |
self.wview(self.item_vid, self.cw_rset, row=row, col=col, vid=vid, **kwargs) |
0 | 284 |
self.w(u'</li>\n') |
285 |
||
1451 | 286 |
|
0 | 287 |
class ListItemView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
288 |
__regid__ = 'listitem' |
1451 | 289 |
|
0 | 290 |
@property |
291 |
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
|
292 |
if self._cw.search_state[0] == 'normal': |
0 | 293 |
return 'outofcontext' |
294 |
return 'outofcontext-search' |
|
1451 | 295 |
|
0 | 296 |
def cell_call(self, row, col, vid=None, **kwargs): |
297 |
if not vid: |
|
298 |
vid = self.redirect_vid |
|
299 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
300 |
self.wview(vid, self.cw_rset, row=row, col=col, **kwargs) |
0 | 301 |
except NoSelectableObject: |
302 |
if vid == self.redirect_vid: |
|
303 |
raise |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
304 |
self.wview(self.redirect_vid, self.cw_rset, row=row, col=col, **kwargs) |
0 | 305 |
|
306 |
||
307 |
class SimpleListView(ListItemView): |
|
308 |
"""list without bullets""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
309 |
__regid__ = 'simplelist' |
0 | 310 |
redirect_vid = 'incontext' |
311 |
||
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
|
312 |
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
|
313 |
"""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
|
314 |
|
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 |
: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
|
316 |
""" |
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 |
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
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
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
|
323 |
|
0 | 324 |
|
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
325 |
class SameETypeListView(EntityView): |
5222
ed6905d98a5e
[doc/book] more flesh to views/primary view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4536
diff
changeset
|
326 |
"""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
|
327 |
view (for instance, display gallery if only images) |
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
328 |
""" |
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
329 |
__regid__ = 'sameetypelist' |
2645
91c71276f999
F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2472
diff
changeset
|
330 |
__select__ = EntityView.__select__ & one_etype_rset() |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
331 |
item_vid = 'sameetypelistitem' |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
332 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
333 |
@property |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
334 |
def title(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
335 |
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
|
336 |
return display_name(self._cw, etype, form='plural') |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
337 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
338 |
def call(self, **kwargs): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
339 |
"""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
|
340 |
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
|
341 |
if showtitle: |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
342 |
self.w(u'<h1>%s</h1>' % self.title) |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
343 |
super(SameETypeListView, self).call(**kwargs) |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
344 |
|
4507
57927ad07e63
no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4494
diff
changeset
|
345 |
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
|
346 |
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
|
347 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
348 |
|
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
349 |
class SameETypeListItemView(EntityView): |
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
350 |
__regid__ = 'sameetypelistitem' |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
351 |
|
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
|
352 |
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
|
353 |
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
|
354 |
|
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
355 |
|
0 | 356 |
class CSVView(SimpleListView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
357 |
__regid__ = 'csv' |
0 | 358 |
redirect_vid = 'incontext' |
1451 | 359 |
|
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
|
360 |
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
|
361 |
if subvid is None and 'vid' in kwargs: |
6583
4e7325d6b616
[deprecation] add version info
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6455
diff
changeset
|
362 |
warn("[3.9] should give a 'subvid' argument instead of 'vid'", |
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
|
363 |
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
|
364 |
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
|
365 |
kwargs['vid'] = subvid |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
366 |
rset = self.cw_rset |
0 | 367 |
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
|
368 |
self.cell_call(i, 0, **kwargs) |
0 | 369 |
if i < rset.rowcount-1: |
370 |
self.w(u", ") |
|
371 |
||
372 |
||
373 |
class TreeItemView(ListItemView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
374 |
__regid__ = 'treeitem' |
0 | 375 |
|
376 |
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
|
377 |
self.wview('incontext', self.cw_rset, row=row, col=col) |
0 | 378 |
|
379 |
class TextSearchResultView(EntityView): |
|
380 |
"""this view is used to display full-text search |
|
381 |
||
382 |
It tries to highlight part of data where the search word appears. |
|
383 |
||
384 |
XXX: finish me (fixed line width, fixed number of lines, CSS, etc.) |
|
385 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
386 |
__regid__ = 'tsearch' |
0 | 387 |
|
388 |
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
|
389 |
entity = self.cw_rset.complete_entity(row, col) |
0 | 390 |
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
|
391 |
searched = self.cw_rset.searched_text() |
0 | 392 |
if searched is None: |
393 |
return |
|
394 |
searched = searched.lower() |
|
395 |
highlighted = '<b>%s</b>' % searched |
|
396 |
for attr in entity.e_schema.indexable_attributes(): |
|
397 |
try: |
|
1680
39860636e184
use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1653
diff
changeset
|
398 |
value = xml_escape(entity.printable_value(attr, format='text/plain').lower()) |
0 | 399 |
except TransformError, ex: |
400 |
continue |
|
401 |
except: |
|
402 |
continue |
|
403 |
if searched in value: |
|
404 |
contexts = [] |
|
405 |
for ctx in value.split(searched): |
|
406 |
if len(ctx) > 30: |
|
407 |
contexts.append(u'...' + ctx[-30:]) |
|
408 |
else: |
|
409 |
contexts.append(ctx) |
|
410 |
value = u'\n' + highlighted.join(contexts) |
|
1451 | 411 |
self.w(value.replace('\n', '<br/>')) |
0 | 412 |
|
413 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
414 |
class TooltipView(EntityView): |
0 | 415 |
"""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
|
416 |
__regid__ = 'tooltip' |
0 | 417 |
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
|
418 |
self.wview('oneline', self.cw_rset, row=row, col=col) |
0 | 419 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
420 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
421 |
# XXX bw compat |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
422 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
423 |
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
|
424 |
|
0 | 425 |
try: |
426 |
from cubicweb.web.views.tableview import TableView |
|
427 |
TableView = class_moved(TableView) |
|
428 |
except ImportError: |
|
429 |
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
|
430 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
431 |
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
|
432 |
PrimaryView = class_moved(primary.PrimaryView) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
433 |
SideBoxView = class_moved(boxes.SideBoxView) |
1653 | 434 |
XmlView = class_moved(xmlrss.XMLView) |
435 |
XmlItemView = class_moved(xmlrss.XMLItemView) |
|
436 |
XmlRsetView = class_moved(xmlrss.XMLRsetView) |
|
437 |
RssView = class_moved(xmlrss.RSSView) |
|
438 |
RssItemView = class_moved(xmlrss.RSSItemView) |
|
1451 | 439 |
|
6455
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
440 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
441 |
class GroupByView(EntityView): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
442 |
"""grouped view of a result set. The `group_key` method return the group |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
443 |
key of an entities (a string or tuple of string). |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
444 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
445 |
For each group, display a link to entities of this group by generating url |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
446 |
like <basepath>/<key> or <basepath>/<key item 1>/<key item 2>. |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
447 |
""" |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
448 |
__abstrack__ = True |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
449 |
__select__ = EntityView.__select__ & match_kwargs('basepath') |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
450 |
entity_attribute = None |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
451 |
reversed = False |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
452 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
453 |
def index_url(self, basepath, key, **kwargs): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
454 |
if isinstance(key, (list, tuple)): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
455 |
key = '/'.join(key) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
456 |
return self._cw.build_url('%s/%s' % (basepath, key), |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
457 |
**kwargs) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
458 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
459 |
def index_link(self, basepath, key, items): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
460 |
url = self.index_url(basepath, key) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
461 |
if isinstance(key, (list, tuple)): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
462 |
key = ' '.join(key) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
463 |
return tags.a(key, href=url) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
464 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
465 |
def group_key(self, entity, **kwargs): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
466 |
value = getattr(entity, self.entity_attribute) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
467 |
if callable(value): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
468 |
value = value() |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
469 |
return value |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
470 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
471 |
def call(self, basepath, maxentries=None, **kwargs): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
472 |
index = {} |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
473 |
for entity in self.cw_rset.entities(): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
474 |
index.setdefault(self.group_key(entity, **kwargs), []).append(entity) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
475 |
displayed = sorted(index) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
476 |
if self.reversed: |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
477 |
displayed = reversed(displayed) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
478 |
if maxentries is None: |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
479 |
needmore = False |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
480 |
else: |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
481 |
needmore = len(index) > maxentries |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
482 |
displayed = tuple(displayed)[:maxentries] |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
483 |
w = self.w |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
484 |
w(u'<ul class="boxListing">') |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
485 |
for key in displayed: |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
486 |
w(u'<li>%s</li>\n' % |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
487 |
self.index_link(basepath, key, index[key])) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
488 |
if needmore: |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
489 |
url = self._cw.build_url('view', vid=self.__regid__, |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
490 |
rql=self.cw_rset.printable_rql()) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
491 |
w( u'<li>%s</li>\n' % tags.a(u'[%s]' % self._cw._('see more'), |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
492 |
href=url)) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
493 |
w(u'</ul>\n') |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
494 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
495 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
496 |
class ArchiveView(GroupByView): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
497 |
"""archive view of a result set. Links to months are built using a basepath |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
498 |
parameters, eg using url like <basepath>/<year>/<month> |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
499 |
""" |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
500 |
__regid__ = 'cw.archive.by_date' |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
501 |
entity_attribute = 'creation_date' |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
502 |
reversed = True |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
503 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
504 |
def group_key(self, entity, **kwargs): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
505 |
value = super(ArchiveView, self).group_key(entity, **kwargs) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
506 |
return '%04d' % value.year, '%02d' % value.month |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
507 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
508 |
def index_link(self, basepath, key, items): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
509 |
"""represent a single month entry""" |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
510 |
year, month = key |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
511 |
label = u'%s %s [%s]' % (self._cw._(calendar.MONTHNAMES[int(month)-1]), |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
512 |
year, len(items)) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
513 |
etypes = set(entity.__regid__ for entity in items) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
514 |
vtitle = '%s %s' % (', '.join(display_name(self._cw, etype, 'plural') |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
515 |
for etype in etypes), |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
516 |
label) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
517 |
title = self._cw._('archive for %(month)s/%(year)s') % { |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
518 |
'month': month, 'year': year} |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
519 |
url = self.index_url(basepath, key, vtitle=vtitle) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
520 |
return tags.a(label, href=url, title=title) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
521 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
522 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
523 |
class AuthorView(GroupByView): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
524 |
"""author view of a result set. Links to month are built using a basepath |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
525 |
parameters, eg using url like <basepath>/<author> |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
526 |
""" |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
527 |
__regid__ = 'cw.archive.by_author' |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
528 |
entity_attribute = 'creator' |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
529 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
530 |
def group_key(self, entity, **kwargs): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
531 |
value = super(AuthorView, self).group_key(entity, **kwargs) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
532 |
if value: |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
533 |
return value.login |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
534 |
return value |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
535 |
|
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
536 |
def index_link(self, basepath, key, items): |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
537 |
label = u'%s [%s]' % (key, len(items)) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
538 |
etypes = set(entity.__regid__ for entity in items) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
539 |
vtitle = self._cw._('%(etype)s by %(author)s') % { |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
540 |
'etype': ', '.join(display_name(self._cw, etype, 'plural') |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
541 |
for etype in etypes), |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
542 |
'author': label} |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
543 |
url = self.index_url(basepath, key, vtitle=vtitle) |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
544 |
title = self._cw._('archive for %(author)s') % {'author': key} |
3282742dd4c6
[baseviews] new cw.archive.[by_author|by_date] views, extracted from blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5518
diff
changeset
|
545 |
return tags.a(label, href=url, title=title) |