author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Mar 2010 08:32:32 +0100 | |
branch | stable |
changeset 5032 | e3fa27fc0d9a |
parent 4994 | 108bb7f2a171 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
1 |
"""base xml and rss views |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
2 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3689
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1882
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
__docformat__ = "restructuredtext en" |
1882 | 9 |
_ = unicode |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
10 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
from time import timezone |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
13 |
from logilab.mtconverter import xml_escape |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
15 |
from cubicweb.selectors import non_final_entity, one_line_rset, appobject_selectable |
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
|
16 |
from cubicweb.view import EntityView, AnyRsetView, Component |
4023
eae23c40627a
drop common subpackage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
17 |
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
|
18 |
from cubicweb.web import httpcache, box |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
19 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
20 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
21 |
# base xml views ############################################################## |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
22 |
|
1652 | 23 |
class XMLView(EntityView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
24 |
"""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
|
25 |
__regid__ = 'xml' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
title = _('xml') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
xml_root = 'rset' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
item_vid = 'xmlitem' |
1477 | 31 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
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
|
33 |
self.wview(self.item_vid, self.cw_rset, row=row, col=col) |
1477 | 34 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
"""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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
self.cell_call(i, 0) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
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
|
42 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
|
1652 | 44 |
class XMLItemView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
45 |
__regid__ = 'xmlitem' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
47 |
def cell_call(self, row, col): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
""" 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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
attr = rschema.type |
4994
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
53 |
if attr == 'eid': |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
54 |
value = entity.eid |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
55 |
else: |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
56 |
try: |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
57 |
value = entity[attr] |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
58 |
except KeyError: |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
59 |
# Bytes |
108bb7f2a171
dont get eid from entity's dict
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4898
diff
changeset
|
60 |
continue |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
if value is not None: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
if attrschema == 'Bytes': |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
from base64 import b64encode |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
value = '<![CDATA[%s]]>' % b64encode(value.getvalue()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
elif isinstance(value, basestring): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
66 |
value = xml_escape(value) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
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
|
68 |
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
|
69 |
|
1477 | 70 |
|
1652 | 71 |
class XMLRsetView(AnyRsetView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
"""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
|
73 |
__regid__ = 'rsetxml' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
74 |
title = _('xml export') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
xml_root = 'rset' |
1477 | 78 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
w = self.w |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
w(u' <row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
for colindex, val in enumerate(row): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
etype = descr[rowindex][colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
tag = labels[colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
attrs = {} |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
if '(' in tag: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
attrs['expr'] = tag |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
tag = 'funccall' |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3165
diff
changeset
|
95 |
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
|
96 |
attrs['eid'] = val |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
# 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
|
98 |
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
|
99 |
row=rowindex, col=colindex) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
else: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
101 |
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
|
102 |
col=colindex, format='text/plain') |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
w(simple_sgml_tag(tag, val, **attrs)) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
w(u' </row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
105 |
w(u'</%s>\n' % self.xml_root) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
106 |
|
1477 | 107 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
108 |
# RSS stuff ################################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
109 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
110 |
class RSSFeedURL(Component): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
111 |
__regid__ = 'rss_feed_url' |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
112 |
__select__ = non_final_entity() |
1477 | 113 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
117 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
118 |
class RSSEntityFeedURL(Component): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
119 |
__regid__ = 'rss_feed_url' |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
120 |
__select__ = non_final_entity() & one_line_rset() |
1477 | 121 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
122 |
def feed_url(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
123 |
return self.cw_rset.get_entity(0, 0).rss_feed_url() |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
124 |
|
1477 | 125 |
|
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
|
126 |
class RSSIconBox(box.BoxTemplate): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
127 |
"""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
|
128 |
__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
|
129 |
__select__ = (box.BoxTemplate.__select__ |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
130 |
& appobject_selectable('components', 'rss_feed_url')) |
1477 | 131 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
132 |
visible = False |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
133 |
order = 999 |
1477 | 134 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
135 |
def call(self, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
136 |
try: |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
137 |
rss = self._cw.external_resource('RSS_LOGO') |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
138 |
except KeyError: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
139 |
self.error('missing RSS_LOGO external resource') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
140 |
return |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
141 |
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
|
142 |
rset=self.cw_rset) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
143 |
url = urlgetter.feed_url() |
1135 | 144 |
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
|
145 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
146 |
|
1652 | 147 |
class RSSView(XMLView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
148 |
__regid__ = 'rss' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
149 |
title = _('rss') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
151 |
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
|
152 |
http_cache_manager = httpcache.MaxAgeHTTPCacheManager |
1477 | 153 |
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
|
154 |
item_vid = 'rssitem' |
1477 | 155 |
|
156 |
def _open(self): |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
157 |
req = self._cw |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
158 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding) |
1477 | 159 |
self.w(u'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n') |
160 |
self.w(u' <channel>\n') |
|
1733 | 161 |
self.w(u' <title>%s RSS Feed</title>\n' |
162 |
% xml_escape(self.page_title())) |
|
163 |
self.w(u' <description>%s</description>\n' |
|
164 |
% xml_escape(req.form.get('vtitle', ''))) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
params = req.form.copy() |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
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
|
167 |
self.w(u' <link>%s</link>\n' % xml_escape(self._cw.build_url(**params))) |
1477 | 168 |
|
169 |
def _close(self): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
170 |
self.w(u' </channel>\n') |
1477 | 171 |
self.w(u'</rss>') |
172 |
||
173 |
def call(self): |
|
174 |
"""display a list of entities by calling their <item_vid> view""" |
|
175 |
self._open() |
|
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3377
diff
changeset
|
176 |
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
|
177 |
self.cell_call(i, 0) |
1477 | 178 |
self._close() |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
179 |
|
1477 | 180 |
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
|
181 |
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
|
182 |
|
1550 | 183 |
|
1652 | 184 |
class RSSItemView(EntityView): |
3377
dd9d292b6a6d
use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3185
diff
changeset
|
185 |
__regid__ = 'rssitem' |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
186 |
date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600) |
1477 | 187 |
add_div_section = False |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
188 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
189 |
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
|
190 |
entity = self.cw_rset.complete_entity(row, col) |
1477 | 191 |
self.w(u'<item>\n') |
1733 | 192 |
self.w(u'<guid isPermaLink="true">%s</guid>\n' |
193 |
% xml_escape(entity.absolute_url())) |
|
1477 | 194 |
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
|
195 |
self.render_description(entity) |
1477 | 196 |
self._marker('dc:date', entity.dc_date(self.date_format)) |
197 |
self.render_entity_creator(entity) |
|
198 |
self.w(u'</item>\n') |
|
199 |
||
4785
1fa7363c78bd
add render_description method to RSSItemView to improve modularity.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4252
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
|
1477 | 203 |
def render_title_link(self, entity): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
204 |
self._marker('title', entity.dc_long_title()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
205 |
self._marker('link', entity.absolute_url()) |
1477 | 206 |
|
207 |
def render_entity_creator(self, entity): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
208 |
if entity.creator: |
1477 | 209 |
self._marker('dc:creator', entity.dc_creator()) |
210 |
||
211 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
212 |
def _marker(self, marker, value): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
213 |
if value: |
1550 | 214 |
self.w(u' <%s>%s</%s>\n' % (marker, xml_escape(value), marker)) |