author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 13 Sep 2011 15:41:11 +0200 | |
changeset 7784 | 7f5c455ec7d1 |
parent 7310 | 5c8cf002919d |
child 7815 | 2a164a9cf81c |
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 |
||
6883 | 34 |
from logilab.mtconverter import TransformError, 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: |
7290
f2051e08cbff
[primary view] display entity source in 'metadata' view if it's not the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6883
diff
changeset
|
204 |
if entity.creation_date: |
f2051e08cbff
[primary view] display entity source in 'metadata' view if it's not the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6883
diff
changeset
|
205 |
self.w(u' <span>%s</span> ' % _('by')) |
f2051e08cbff
[primary view] display entity source in 'metadata' view if it's not the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6883
diff
changeset
|
206 |
else: |
7310
5c8cf002919d
[primary, metadata] reuse existing msgids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7290
diff
changeset
|
207 |
self.w(u' <span>%s</span> ' % _('created_by')) |
0 | 208 |
self.w(u'<span class="value">%s</span>' % entity.creator.name()) |
7290
f2051e08cbff
[primary view] display entity source in 'metadata' view if it's not the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6883
diff
changeset
|
209 |
meta = entity.cw_metainformation() |
f2051e08cbff
[primary view] display entity source in 'metadata' view if it's not the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6883
diff
changeset
|
210 |
if meta['source']['uri'] != 'system': |
7310
5c8cf002919d
[primary, metadata] reuse existing msgids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7290
diff
changeset
|
211 |
self.w(u' (<span>%s</span>' % _('cw_source')) |
7290
f2051e08cbff
[primary view] display entity source in 'metadata' view if it's not the system source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6883
diff
changeset
|
212 |
self.w(u' <span class="value">%s</span>)' % meta['source']['uri']) |
0 | 213 |
self.w(u'</div>') |
214 |
||
215 |
||
216 |
class InContextTextView(TextView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
217 |
__regid__ = 'textincontext' |
0 | 218 |
title = None # not listed as a possible view |
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_title()) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
222 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
223 |
|
0 | 224 |
class OutOfContextTextView(InContextTextView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
225 |
__regid__ = 'textoutofcontext' |
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 |
self.w(entity.dc_long_title()) |
230 |
||
231 |
||
232 |
class InContextView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
233 |
__regid__ = 'incontext' |
0 | 234 |
|
235 |
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
|
236 |
entity = self.cw_rset.get_entity(row, col) |
0 | 237 |
desc = cut(entity.dc_description(), 50) |
1882 | 238 |
self.w(u'<a href="%s" title="%s">' % ( |
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
239 |
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
|
240 |
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
|
241 |
row=row, col=col))) |
0 | 242 |
self.w(u'</a>') |
243 |
||
1451 | 244 |
|
0 | 245 |
class OutOfContextView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
246 |
__regid__ = 'outofcontext' |
0 | 247 |
|
248 |
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
|
249 |
entity = self.cw_rset.get_entity(row, col) |
1882 | 250 |
desc = cut(entity.dc_description(), 50) |
251 |
self.w(u'<a href="%s" title="%s">' % ( |
|
2312
af4d8f75c5db
use xml_escape
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
252 |
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
|
253 |
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
|
254 |
row=row, col=col))) |
0 | 255 |
self.w(u'</a>') |
256 |
||
257 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
258 |
# list views ################################################################## |
0 | 259 |
|
260 |
class ListView(EntityView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
261 |
__regid__ = 'list' |
0 | 262 |
title = _('list') |
263 |
item_vid = 'listitem' |
|
1451 | 264 |
|
0 | 265 |
def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs): |
266 |
"""display a list of entities by calling their <item_vid> view |
|
1451 | 267 |
|
0 | 268 |
:param listid: the DOM id to use for the root element |
269 |
""" |
|
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
270 |
# 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
|
271 |
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
|
272 |
subvid = self._cw.form.pop('subvid') # consume it |
0 | 273 |
if listid: |
274 |
listid = u' id="%s"' % listid |
|
275 |
else: |
|
276 |
listid = u'' |
|
277 |
if title: |
|
278 |
self.w(u'<div%s class="%s"><h4>%s</h4>\n' % (listid, klass or 'section', title)) |
|
279 |
self.w(u'<ul>\n') |
|
280 |
else: |
|
281 |
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
|
282 |
for i in xrange(self.cw_rset.rowcount): |
0 | 283 |
self.cell_call(row=i, col=0, vid=subvid, **kwargs) |
284 |
self.w(u'</ul>\n') |
|
285 |
if title: |
|
286 |
self.w(u'</div>\n') |
|
287 |
||
288 |
def cell_call(self, row, col=0, vid=None, **kwargs): |
|
289 |
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
|
290 |
self.wview(self.item_vid, self.cw_rset, row=row, col=col, vid=vid, **kwargs) |
0 | 291 |
self.w(u'</li>\n') |
292 |
||
1451 | 293 |
|
0 | 294 |
class ListItemView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
295 |
__regid__ = 'listitem' |
1451 | 296 |
|
0 | 297 |
@property |
298 |
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
|
299 |
if self._cw.search_state[0] == 'normal': |
0 | 300 |
return 'outofcontext' |
301 |
return 'outofcontext-search' |
|
1451 | 302 |
|
0 | 303 |
def cell_call(self, row, col, vid=None, **kwargs): |
304 |
if not vid: |
|
305 |
vid = self.redirect_vid |
|
306 |
try: |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
307 |
self.wview(vid, self.cw_rset, row=row, col=col, **kwargs) |
0 | 308 |
except NoSelectableObject: |
309 |
if vid == self.redirect_vid: |
|
310 |
raise |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
311 |
self.wview(self.redirect_vid, self.cw_rset, row=row, col=col, **kwargs) |
0 | 312 |
|
313 |
||
314 |
class SimpleListView(ListItemView): |
|
315 |
"""list without bullets""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
316 |
__regid__ = 'simplelist' |
0 | 317 |
redirect_vid = 'incontext' |
318 |
||
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
|
319 |
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
|
320 |
"""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
|
321 |
|
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 |
: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
|
323 |
""" |
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
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
|
0 | 331 |
|
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
332 |
class SameETypeListView(EntityView): |
5222
ed6905d98a5e
[doc/book] more flesh to views/primary view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4536
diff
changeset
|
333 |
"""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
|
334 |
view (for instance, display gallery if only images) |
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
335 |
""" |
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
336 |
__regid__ = 'sameetypelist' |
2645
91c71276f999
F [adapted list view] fix selector
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2472
diff
changeset
|
337 |
__select__ = EntityView.__select__ & one_etype_rset() |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
338 |
item_vid = 'sameetypelistitem' |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
339 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
340 |
@property |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
341 |
def title(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
342 |
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
|
343 |
return display_name(self._cw, etype, form='plural') |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
344 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
345 |
def call(self, **kwargs): |
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
346 |
"""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
|
347 |
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
|
348 |
if showtitle: |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
349 |
self.w(u'<h1>%s</h1>' % self.title) |
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
350 |
super(SameETypeListView, self).call(**kwargs) |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
351 |
|
4507
57927ad07e63
no need for a specific vid argument here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4494
diff
changeset
|
352 |
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
|
353 |
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
|
354 |
|
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
355 |
|
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
356 |
class SameETypeListItemView(EntityView): |
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
357 |
__regid__ = 'sameetypelistitem' |
2469
b87c4d150e09
new adaptedlist view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2468
diff
changeset
|
358 |
|
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
|
359 |
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
|
360 |
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
|
361 |
|
4494
ccb7fce7297b
AdaptedList -> SameETypeList
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4482
diff
changeset
|
362 |
|
0 | 363 |
class CSVView(SimpleListView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
364 |
__regid__ = 'csv' |
0 | 365 |
redirect_vid = 'incontext' |
1451 | 366 |
|
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 |
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
|
368 |
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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
kwargs['vid'] = subvid |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3418
diff
changeset
|
373 |
rset = self.cw_rset |
0 | 374 |
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
|
375 |
self.cell_call(i, 0, **kwargs) |
0 | 376 |
if i < rset.rowcount-1: |
377 |
self.w(u", ") |
|
378 |
||
379 |
||
380 |
class TreeItemView(ListItemView): |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
381 |
__regid__ = 'treeitem' |
0 | 382 |
|
383 |
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
|
384 |
self.wview('incontext', self.cw_rset, row=row, col=col) |
0 | 385 |
|
386 |
class TextSearchResultView(EntityView): |
|
387 |
"""this view is used to display full-text search |
|
388 |
||
389 |
It tries to highlight part of data where the search word appears. |
|
390 |
||
391 |
XXX: finish me (fixed line width, fixed number of lines, CSS, etc.) |
|
392 |
""" |
|
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3293
diff
changeset
|
393 |
__regid__ = 'tsearch' |
0 | 394 |
|
395 |
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
|
396 |
entity = self.cw_rset.complete_entity(row, col) |
0 | 397 |
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
|
398 |
searched = self.cw_rset.searched_text() |
0 | 399 |
if searched is None: |
400 |
return |
|
401 |
searched = searched.lower() |
|
402 |
highlighted = '<b>%s</b>' % searched |
|
403 |
for attr in entity.e_schema.indexable_attributes(): |
|
404 |
try: |
|
1680
39860636e184
use xml_escape
Graziella Toutoungis <graziella.toutoungis@logilab.fr>
parents:
1653
diff
changeset
|
405 |
value = xml_escape(entity.printable_value(attr, format='text/plain').lower()) |
0 | 406 |
except TransformError, ex: |
407 |
continue |
|
408 |
except: |
|
409 |
continue |
|
410 |
if searched in value: |
|
411 |
contexts = [] |
|
412 |
for ctx in value.split(searched): |
|
413 |
if len(ctx) > 30: |
|
414 |
contexts.append(u'...' + ctx[-30:]) |
|
415 |
else: |
|
416 |
contexts.append(ctx) |
|
417 |
value = u'\n' + highlighted.join(contexts) |
|
1451 | 418 |
self.w(value.replace('\n', '<br/>')) |
0 | 419 |
|
420 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
421 |
class TooltipView(EntityView): |
0 | 422 |
"""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
|
423 |
__regid__ = 'tooltip' |
0 | 424 |
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
|
425 |
self.wview('oneline', self.cw_rset, row=row, col=col) |
0 | 426 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
427 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
428 |
# XXX bw compat |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
429 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
430 |
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
|
431 |
|
0 | 432 |
try: |
433 |
from cubicweb.web.views.tableview import TableView |
|
434 |
TableView = class_moved(TableView) |
|
435 |
except ImportError: |
|
436 |
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
|
437 |
|
1491
742aff97dbf7
move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
1477
diff
changeset
|
438 |
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
|
439 |
PrimaryView = class_moved(primary.PrimaryView) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
795
diff
changeset
|
440 |
SideBoxView = class_moved(boxes.SideBoxView) |
1653 | 441 |
XmlView = class_moved(xmlrss.XMLView) |
442 |
XmlItemView = class_moved(xmlrss.XMLItemView) |
|
443 |
XmlRsetView = class_moved(xmlrss.XMLRsetView) |
|
444 |
RssView = class_moved(xmlrss.RSSView) |
|
445 |
RssItemView = class_moved(xmlrss.RSSItemView) |
|
1451 | 446 |
|
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
|
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 |
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
|
449 |
"""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
|
450 |
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
|
451 |
|
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 |
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
|
453 |
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
|
454 |
""" |
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 |
__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
|
456 |
__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
|
457 |
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
|
458 |
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
|
459 |
|
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 |
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
|
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 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
|
464 |
**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
|
465 |
|
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 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
|
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 |
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
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
|
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 |
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
|
479 |
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
|
480 |
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
|
481 |
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
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
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
|
499 |
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
|
500 |
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
|
501 |
|
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 |
|
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 |
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
|
504 |
"""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
|
505 |
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
|
506 |
""" |
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 |
__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
|
508 |
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
|
509 |
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
|
510 |
|
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 |
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
|
512 |
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
|
513 |
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
|
514 |
|
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 |
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
|
516 |
"""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
|
517 |
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
|
518 |
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
|
519 |
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
|
520 |
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
|
521 |
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
|
522 |
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
|
523 |
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
|
524 |
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
|
525 |
'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
|
526 |
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
|
527 |
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
|
528 |
|
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 |
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
|
531 |
"""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
|
532 |
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
|
533 |
""" |
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 |
__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
|
535 |
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
|
536 |
|
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 |
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
|
538 |
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
|
539 |
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
|
540 |
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
|
541 |
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
|
542 |
|
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 |
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
|
544 |
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
|
545 |
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
|
546 |
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
|
547 |
'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
|
548 |
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
|
549 |
'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
|
550 |
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
|
551 |
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
|
552 |
return tags.a(label, href=url, title=title) |