author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Mon, 27 Jul 2009 15:19:01 +0200 | |
changeset 2524 | 2d0c04c8cbe4 |
parent 2234 | 1fbcf202882d |
child 2650 | 18aec79ec3a3 |
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 |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1882
diff
changeset
|
4 |
:copyright: 2001-2009 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 |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
17 |
from cubicweb.common.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""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
25 |
id = 'xml' |
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): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
33 |
self.wview(self.item_vid, self.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""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
self.w(u'<%s size="%s">\n' % (self.xml_root, len(self.rset))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
for i in xrange(self.rset.rowcount): |
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): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
id = 'xmlitem' |
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 """ |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
entity = self.complete_entity(row, col) |
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 |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
try: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
value = entity[attr] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
except KeyError: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
# Bytes |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
continue |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
if value is not None: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
if attrschema == 'Bytes': |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
from base64 import b64encode |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
value = '<![CDATA[%s]]>' % b64encode(value.getvalue()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
elif isinstance(value, basestring): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
value = xml_escape(value) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
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
|
65 |
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
|
66 |
|
1477 | 67 |
|
1652 | 68 |
class XMLRsetView(AnyRsetView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
"""dumps raw rset as xml""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
id = 'rsetxml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
title = _('xml export') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
74 |
xml_root = 'rset' |
1477 | 75 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
w = self.w |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
rset, descr = self.rset, self.rset.description |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
eschema = self.schema.eschema |
2205
fc1447fe94df
tr is now the second argument
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
80 |
labels = self.columns_labels(tr=False) |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
w(u'<?xml version="1.0" encoding="%s"?>\n' % self.req.encoding) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
w(u'<%s query="%s">\n' % (self.xml_root, xml_escape(rset.printable_rql()))) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
for rowindex, row in enumerate(self.rset): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
w(u' <row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
85 |
for colindex, val in enumerate(row): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
86 |
etype = descr[rowindex][colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
87 |
tag = labels[colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
attrs = {} |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
if '(' in tag: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
attrs['expr'] = tag |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
tag = 'funccall' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
if val is not None and not eschema(etype).is_final(): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
attrs['eid'] = val |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
# csvrow.append(val) # val is eid in that case |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
val = self.view('textincontext', rset, |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
row=rowindex, col=colindex) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
97 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
98 |
val = self.view('final', rset, displaytime=True, |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
row=rowindex, col=colindex, format='text/plain') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
w(simple_sgml_tag(tag, val, **attrs)) |
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 |
w(u'</%s>\n' % self.xml_root) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
103 |
|
1477 | 104 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
105 |
# RSS stuff ################################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
106 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
107 |
class RSSFeedURL(Component): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
108 |
id = 'rss_feed_url' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
109 |
__select__ = non_final_entity() |
1477 | 110 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
111 |
def feed_url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
112 |
return self.build_url(rql=self.limited_rql(), vid='rss') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
113 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
114 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
115 |
class RSSEntityFeedURL(Component): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
116 |
id = 'rss_feed_url' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
117 |
__select__ = non_final_entity() & one_line_rset() |
1477 | 118 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
119 |
def feed_url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
120 |
return self.entity(0, 0).rss_feed_url() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
121 |
|
1477 | 122 |
|
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
|
123 |
class RSSIconBox(box.BoxTemplate): |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
124 |
"""just display the RSS icon on uniform result set""" |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
125 |
id = '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
|
126 |
__select__ = (box.BoxTemplate.__select__ |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
127 |
& appobject_selectable('components', 'rss_feed_url')) |
1477 | 128 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
129 |
visible = False |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
130 |
order = 999 |
1477 | 131 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
132 |
def call(self, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
133 |
try: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
134 |
rss = self.req.external_resource('RSS_LOGO') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
135 |
except KeyError: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
136 |
self.error('missing RSS_LOGO external resource') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
137 |
return |
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
|
138 |
urlgetter = self.vreg.select('components', 'rss_feed_url', |
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
|
139 |
self.req, rset=self.rset) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
140 |
url = urlgetter.feed_url() |
1135 | 141 |
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
|
142 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
143 |
|
1652 | 144 |
class RSSView(XMLView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
145 |
id = 'rss' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
146 |
title = _('rss') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
147 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
148 |
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
|
149 |
http_cache_manager = httpcache.MaxAgeHTTPCacheManager |
1477 | 150 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
151 |
||
152 |
def _open(self): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
153 |
req = self.req |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding) |
1477 | 155 |
self.w(u'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n') |
156 |
self.w(u' <channel>\n') |
|
1733 | 157 |
self.w(u' <title>%s RSS Feed</title>\n' |
158 |
% xml_escape(self.page_title())) |
|
159 |
self.w(u' <description>%s</description>\n' |
|
160 |
% xml_escape(req.form.get('vtitle', ''))) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
161 |
params = req.form.copy() |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
162 |
params.pop('vid', None) |
1550 | 163 |
self.w(u' <link>%s</link>\n' % xml_escape(self.build_url(**params))) |
1477 | 164 |
|
165 |
def _close(self): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
166 |
self.w(u' </channel>\n') |
1477 | 167 |
self.w(u'</rss>') |
168 |
||
169 |
def call(self): |
|
170 |
"""display a list of entities by calling their <item_vid> view""" |
|
171 |
self._open() |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
172 |
for i in xrange(self.rset.rowcount): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
173 |
self.cell_call(i, 0) |
1477 | 174 |
self._close() |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
175 |
|
1477 | 176 |
def cell_call(self, row, col): |
177 |
self.wview('rssitem', self.rset, row=row, col=col) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
178 |
|
1550 | 179 |
|
1652 | 180 |
class RSSItemView(EntityView): |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
181 |
id = 'rssitem' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
182 |
date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600) |
1477 | 183 |
add_div_section = False |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
184 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
185 |
def cell_call(self, row, col): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
186 |
entity = self.complete_entity(row, col) |
1477 | 187 |
self.w(u'<item>\n') |
1733 | 188 |
self.w(u'<guid isPermaLink="true">%s</guid>\n' |
189 |
% xml_escape(entity.absolute_url())) |
|
1477 | 190 |
self.render_title_link(entity) |
1733 | 191 |
self._marker('description', entity.dc_description(format='text/html')) |
1477 | 192 |
self._marker('dc:date', entity.dc_date(self.date_format)) |
193 |
self.render_entity_creator(entity) |
|
194 |
self.w(u'</item>\n') |
|
195 |
||
196 |
def render_title_link(self, entity): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
197 |
self._marker('title', entity.dc_long_title()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
198 |
self._marker('link', entity.absolute_url()) |
1477 | 199 |
|
200 |
def render_entity_creator(self, entity): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
201 |
if entity.creator: |
1477 | 202 |
self._marker('dc:creator', entity.dc_creator()) |
203 |
||
204 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
205 |
def _marker(self, marker, value): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
206 |
if value: |
1550 | 207 |
self.w(u' <%s>%s</%s>\n' % (marker, xml_escape(value), marker)) |