author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 02 Jun 2010 15:29:18 +0200 | |
changeset 5633 | 879590c52679 |
parent 5569 | cb14af012a96 |
child 5877 | 0c7b7b76a84f |
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
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:
4994
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
18 |
"""base xml and rss views""" |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
20 |
__docformat__ = "restructuredtext en" |
1882 | 21 |
_ = unicode |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
23 |
from time import timezone |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
from logilab.mtconverter import xml_escape |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
27 |
from cubicweb.selectors import (implements, non_final_entity, one_line_rset, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
28 |
appobject_selectable, adaptable) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
29 |
from cubicweb.view import EntityView, EntityAdapter, AnyRsetView, Component |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
30 |
from cubicweb.view import implements_adapter_compat |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
31 |
from cubicweb.uilib import simple_sgml_tag |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
32 |
from cubicweb.web import httpcache, box |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
34 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
35 |
# base xml views ############################################################## |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
|
1652 | 37 |
class XMLView(EntityView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
"""xml view for entities""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
39 |
__regid__ = 'xml' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
title = _('xml') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
xml_root = 'rset' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
44 |
item_vid = 'xmlitem' |
1477 | 45 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
47 |
self.wview(self.item_vid, self.cw_rset, row=row, col=col) |
1477 | 48 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
"""display a list of entities by calling their <item_vid> view""" |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
51 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
52 |
self.w(u'<%s size="%s">\n' % (self.xml_root, len(self.cw_rset))) |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
53 |
for i in xrange(self.cw_rset.rowcount): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
self.cell_call(i, 0) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
self.w(u'</%s>\n' % self.xml_root) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
|
1652 | 58 |
class XMLItemView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
59 |
__regid__ = 'xmlitem' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
def cell_call(self, row, col): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
""" element as an item for an xml feed """ |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
63 |
entity = self.cw_rset.complete_entity(row, col) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
self.w(u'<%s>\n' % (entity.e_schema)) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
for rschema, attrschema in entity.e_schema.attribute_definitions(): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
66 |
attr = rschema.type |
4994
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
67 |
if attr == 'eid': |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
68 |
value = entity.eid |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
69 |
else: |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
70 |
try: |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
71 |
value = entity[attr] |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
72 |
except KeyError: |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
73 |
# Bytes |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
74 |
continue |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
if value is not None: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
if attrschema == 'Bytes': |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
from base64 import b64encode |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
value = '<![CDATA[%s]]>' % b64encode(value.getvalue()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
elif isinstance(value, basestring): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
value = xml_escape(value) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
self.w(u' <%s>%s</%s>\n' % (attr, value, attr)) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
self.w(u'</%s>\n' % (entity.e_schema)) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
|
1477 | 84 |
|
1652 | 85 |
class XMLRsetView(AnyRsetView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
86 |
"""dumps raw rset as xml""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
87 |
__regid__ = 'rsetxml' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
title = _('xml export') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
xml_root = 'rset' |
1477 | 92 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
w = self.w |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
95 |
rset, descr = self.cw_rset, self.cw_rset.description |
4045
f4a52abb6f4f
cw 3.6 api update
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
4023
diff
changeset
|
96 |
eschema = self._cw.vreg.schema.eschema |
2205
fc1447fe94df
tr is now the second argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
97 |
labels = self.columns_labels(tr=False) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
98 |
w(u'<?xml version="1.0" encoding="%s"?>\n' % self._cw.encoding) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
w(u'<%s query="%s">\n' % (self.xml_root, xml_escape(rset.printable_rql()))) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
100 |
for rowindex, row in enumerate(self.cw_rset): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
101 |
w(u' <row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
102 |
for colindex, val in enumerate(row): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
etype = descr[rowindex][colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
tag = labels[colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
105 |
attrs = {} |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
106 |
if '(' in tag: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
107 |
attrs['expr'] = tag |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
108 |
tag = 'funccall' |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3165
diff
changeset
|
109 |
if val is not None and not eschema(etype).final: |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
110 |
attrs['eid'] = val |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
111 |
# csvrow.append(val) # val is eid in that case |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
112 |
val = self._cw.view('textincontext', rset, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
113 |
row=rowindex, col=colindex) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
115 |
val = self._cw.view('final', rset, row=rowindex, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
116 |
col=colindex, format='text/plain') |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
117 |
w(simple_sgml_tag(tag, val, **attrs)) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
118 |
w(u' </row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
w(u'</%s>\n' % self.xml_root) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
120 |
|
1477 | 121 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
122 |
# RSS stuff ################################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
123 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
124 |
class IFeedAdapter(EntityAdapter): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
125 |
__regid__ = 'IFeed' |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
126 |
__select__ = implements('Any') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
127 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
128 |
@implements_adapter_compat('IFeed') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
129 |
def rss_feed_url(self): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
130 |
"""return an url to the rss feed for this entity""" |
5569
cb14af012a96
[adapters] refactoring fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
131 |
return self.entity.absolute_url(vid='rss') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
132 |
|
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
133 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
134 |
class RSSFeedURL(Component): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
135 |
__regid__ = 'rss_feed_url' |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
136 |
__select__ = non_final_entity() |
1477 | 137 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
138 |
def feed_url(self): |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
139 |
return self._cw.build_url(rql=self.cw_rset.limited_rql(), vid='rss') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
140 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
141 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
142 |
class RSSEntityFeedURL(Component): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
143 |
__regid__ = 'rss_feed_url' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
144 |
__select__ = one_line_rset() & adaptable('IFeed') |
1477 | 145 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
146 |
def feed_url(self): |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
147 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5467
diff
changeset
|
148 |
return entity.cw_adapt_to('IFeed').rss_feed_url() |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
149 |
|
1477 | 150 |
|
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
151 |
class RSSIconBox(box.BoxTemplate): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
152 |
"""just display the RSS icon on uniform result set""" |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
153 |
__regid__ = 'rss' |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
154 |
__select__ = (box.BoxTemplate.__select__ |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
155 |
& appobject_selectable('components', 'rss_feed_url')) |
1477 | 156 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
157 |
visible = False |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
158 |
order = 999 |
1477 | 159 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
160 |
def call(self, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
161 |
try: |
5467
57372dbfd114
[https] fix resource urls in https version of a site: should use the https version as well to avoid warnings from the nrowser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5444
diff
changeset
|
162 |
rss = self._cw.uiprops['RSS_LOGO'] |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
163 |
except KeyError: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
164 |
self.error('missing RSS_LOGO external resource') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
165 |
return |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
166 |
urlgetter = self._cw.vreg['components'].select('rss_feed_url', self._cw, |
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
167 |
rset=self.cw_rset) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
168 |
url = urlgetter.feed_url() |
1135 | 169 |
self.w(u'<a href="%s"><img src="%s" alt="rss"/></a>\n' % (xml_escape(url), rss)) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
170 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
171 |
|
1652 | 172 |
class RSSView(XMLView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
173 |
__regid__ = 'rss' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
title = _('rss') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
175 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
176 |
content_type = 'text/xml' |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
177 |
http_cache_manager = httpcache.MaxAgeHTTPCacheManager |
1477 | 178 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
4898
5dec0d400d08
Add a rssitem_id attribut to RSSView to easly choose the view used for items.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4785
diff
changeset
|
179 |
item_vid = 'rssitem' |
1477 | 180 |
|
181 |
def _open(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
182 |
req = self._cw |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
183 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding) |
1477 | 184 |
self.w(u'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n') |
185 |
self.w(u' <channel>\n') |
|
1733 | 186 |
self.w(u' <title>%s RSS Feed</title>\n' |
187 |
% xml_escape(self.page_title())) |
|
188 |
self.w(u' <description>%s</description>\n' |
|
189 |
% xml_escape(req.form.get('vtitle', ''))) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
190 |
params = req.form.copy() |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
191 |
params.pop('vid', None) |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
192 |
self.w(u' <link>%s</link>\n' % xml_escape(self._cw.build_url(**params))) |
1477 | 193 |
|
194 |
def _close(self): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
195 |
self.w(u' </channel>\n') |
1477 | 196 |
self.w(u'</rss>') |
197 |
||
198 |
def call(self): |
|
199 |
"""display a list of entities by calling their <item_vid> view""" |
|
200 |
self._open() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
201 |
for i in xrange(self.cw_rset.rowcount): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
202 |
self.cell_call(i, 0) |
1477 | 203 |
self._close() |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
204 |
|
1477 | 205 |
def cell_call(self, row, col): |
4898
5dec0d400d08
Add a rssitem_id attribut to RSSView to easly choose the view used for items.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4785
diff
changeset
|
206 |
self.wview(self.item_vid, self.cw_rset, row=row, col=col) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
207 |
|
1550 | 208 |
|
1652 | 209 |
class RSSItemView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
210 |
__regid__ = 'rssitem' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
211 |
date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600) |
1477 | 212 |
add_div_section = False |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
213 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
214 |
def cell_call(self, row, col): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
215 |
entity = self.cw_rset.complete_entity(row, col) |
1477 | 216 |
self.w(u'<item>\n') |
1733 | 217 |
self.w(u'<guid isPermaLink="true">%s</guid>\n' |
218 |
% xml_escape(entity.absolute_url())) |
|
1477 | 219 |
self.render_title_link(entity) |
4785
1fa7363c78bd
add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
220 |
self.render_description(entity) |
1477 | 221 |
self._marker('dc:date', entity.dc_date(self.date_format)) |
222 |
self.render_entity_creator(entity) |
|
223 |
self.w(u'</item>\n') |
|
224 |
||
4785
1fa7363c78bd
add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
225 |
def render_description(self, entity): |
1fa7363c78bd
add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
226 |
self._marker('description', entity.dc_description(format='text/html')) |
1fa7363c78bd
add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
227 |
|
1477 | 228 |
def render_title_link(self, entity): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
229 |
self._marker('title', entity.dc_long_title()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
230 |
self._marker('link', entity.absolute_url()) |
1477 | 231 |
|
232 |
def render_entity_creator(self, entity): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
233 |
if entity.creator: |
1477 | 234 |
self._marker('dc:creator', entity.dc_creator()) |
235 |
||
236 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
237 |
def _marker(self, marker, value): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
238 |
if value: |
1550 | 239 |
self.w(u' <%s>%s</%s>\n' % (marker, xml_escape(value), marker)) |