author | sylvain.thenault@logilab.fr |
Thu, 30 Apr 2009 00:39:09 +0200 | |
branch | tls-sprint |
changeset 1550 | 8260e857822b |
parent 1477 | b056a49c16dc |
child 1652 | ba0a6b4d04f7 |
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 |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
6 |
""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
__docformat__ = "restructuredtext en" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
from time import timezone |
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 logilab.mtconverter import xml_escape |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
12 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
13 |
from cubicweb.selectors import non_final_entity, one_line_rset, appobject_selectable |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
14 |
from cubicweb.view import EntityView, AnyRsetView |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
from cubicweb.web.httpcache import MaxAgeHTTPCacheManager |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
16 |
from cubicweb.web.component import Component |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
17 |
from cubicweb.web.box import BoxTemplate |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
18 |
from cubicweb.common.uilib import simple_sgml_tag |
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 |
_ = unicode |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
21 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
22 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
23 |
# base xml views ############################################################## |
824
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 |
class XmlView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
"""xml view for entities""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
27 |
id = 'xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
title = _('xml') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
31 |
xml_root = 'rset' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
item_vid = 'xmlitem' |
1477 | 33 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
def cell_call(self, row, col): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
self.wview(self.item_vid, self.rset, row=row, col=col) |
1477 | 36 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
"""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
|
39 |
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
|
40 |
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
|
41 |
for i in xrange(self.rset.rowcount): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
self.cell_call(i, 0) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
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
|
44 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
46 |
class XmlItemView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
47 |
id = 'xmlitem' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
def cell_call(self, row, col): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
""" 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
|
51 |
entity = self.complete_entity(row, col) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
attr = rschema.type |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
try: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
value = entity[attr] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
except KeyError: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
# Bytes |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
continue |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
if value is not None: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
if attrschema == 'Bytes': |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
from base64 import b64encode |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
value = '<![CDATA[%s]]>' % b64encode(value.getvalue()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
elif isinstance(value, basestring): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
65 |
value = xml_escape(value) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
|
1477 | 69 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
class XmlRsetView(AnyRsetView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
"""dumps raw rset as xml""" |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
id = 'rsetxml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
title = _('xml export') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
74 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
xml_root = 'rset' |
1477 | 77 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
78 |
def call(self): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
w = self.w |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
rset, descr = self.rset, self.rset.description |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
eschema = self.schema.eschema |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
82 |
labels = self.columns_labels(False) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
for rowindex, row in enumerate(self.rset): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
86 |
w(u' <row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
87 |
for colindex, val in enumerate(row): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
88 |
etype = descr[rowindex][colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
89 |
tag = labels[colindex] |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
90 |
attrs = {} |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
91 |
if '(' in tag: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
attrs['expr'] = tag |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
tag = 'funccall' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
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
|
95 |
attrs['eid'] = val |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
# 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
|
97 |
val = self.view('textincontext', rset, |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
98 |
row=rowindex, col=colindex) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
99 |
else: |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
100 |
val = self.view('final', rset, displaytime=True, |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
101 |
row=rowindex, col=colindex, format='text/plain') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
102 |
w(simple_sgml_tag(tag, val, **attrs)) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
w(u' </row>\n') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
104 |
w(u'</%s>\n' % self.xml_root) |
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
105 |
|
1477 | 106 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
107 |
# RSS stuff ################################################################### |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
108 |
|
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
109 |
class RSSFeedURL(Component): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
110 |
id = 'rss_feed_url' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
111 |
__select__ = non_final_entity() |
1477 | 112 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
113 |
def feed_url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
114 |
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
|
115 |
|
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 |
class RSSEntityFeedURL(Component): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
118 |
id = 'rss_feed_url' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
119 |
__select__ = non_final_entity() & one_line_rset() |
1477 | 120 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
121 |
def feed_url(self): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
122 |
return self.entity(0, 0).rss_feed_url() |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
123 |
|
1477 | 124 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
125 |
class RSSIconBox(BoxTemplate): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
126 |
"""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
|
127 |
id = 'rss' |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
128 |
__select__ = (BoxTemplate.__select__ |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
129 |
& appobject_selectable('components', 'rss_feed_url')) |
1477 | 130 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
131 |
visible = False |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
132 |
order = 999 |
1477 | 133 |
|
1091
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
134 |
def call(self, **kwargs): |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
135 |
try: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
136 |
rss = self.req.external_resource('RSS_LOGO') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
137 |
except KeyError: |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
138 |
self.error('missing RSS_LOGO external resource') |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
139 |
return |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
140 |
urlgetter = self.vreg.select_component('rss_feed_url', self.req, self.rset) |
b5e253c0dd13
a bit of reorganisation inside web/views:
sylvain.thenault@logilab.fr
parents:
824
diff
changeset
|
141 |
url = urlgetter.feed_url() |
1135 | 142 |
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
|
143 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
145 |
class RssView(XmlView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
146 |
id = 'rss' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
147 |
title = _('rss') |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
148 |
templatable = False |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
149 |
content_type = 'text/xml' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
http_cache_manager = MaxAgeHTTPCacheManager |
1477 | 151 |
cache_max_age = 60*60*2 # stay in http cache for 2 hours by default |
152 |
||
153 |
def _open(self): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
154 |
req = self.req |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
self.w(u'<?xml version="1.0" encoding="%s"?>\n' % req.encoding) |
1477 | 156 |
self.w(u'<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">\n') |
157 |
self.w(u' <channel>\n') |
|
1550 | 158 |
self.w(u' <title>%s RSS Feed</title>\n' % xml_escape(self.page_title())) |
159 |
self.w(u' <description>%s</description>\n' % xml_escape(req.form.get('vtitle', ''))) |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
160 |
params = req.form.copy() |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
161 |
params.pop('vid', None) |
1550 | 162 |
self.w(u' <link>%s</link>\n' % xml_escape(self.build_url(**params))) |
1477 | 163 |
|
164 |
def _close(self): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
165 |
self.w(u' </channel>\n') |
1477 | 166 |
self.w(u'</rss>') |
167 |
||
168 |
def call(self): |
|
169 |
"""display a list of entities by calling their <item_vid> view""" |
|
170 |
self._open() |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
171 |
for i in xrange(self.rset.rowcount): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
172 |
self.cell_call(i, 0) |
1477 | 173 |
self._close() |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
174 |
|
1477 | 175 |
def cell_call(self, row, col): |
176 |
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
|
177 |
|
1550 | 178 |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
179 |
class RssItemView(EntityView): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
180 |
id = 'rssitem' |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
181 |
date_format = '%%Y-%%m-%%dT%%H:%%M%+03i:00' % (timezone / 3600) |
1477 | 182 |
add_div_section = False |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
183 |
|
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
184 |
def cell_call(self, row, col): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
185 |
entity = self.complete_entity(row, col) |
1477 | 186 |
self.w(u'<item>\n') |
1550 | 187 |
self.w(u'<guid isPermaLink="true">%s</guid>\n' % xml_escape(entity.absolute_url())) |
1477 | 188 |
self.render_title_link(entity) |
1550 | 189 |
self._marker('description', xml_escape(entity.dc_description())) |
1477 | 190 |
self._marker('dc:date', entity.dc_date(self.date_format)) |
191 |
self.render_entity_creator(entity) |
|
192 |
self.w(u'</item>\n') |
|
193 |
||
194 |
def render_title_link(self, entity): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
195 |
self._marker('title', entity.dc_long_title()) |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
196 |
self._marker('link', entity.absolute_url()) |
1477 | 197 |
|
198 |
def render_entity_creator(self, entity): |
|
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
199 |
if entity.creator: |
1477 | 200 |
self._marker('dc:creator', entity.dc_creator()) |
201 |
||
202 |
||
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
203 |
def _marker(self, marker, value): |
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
204 |
if value: |
1550 | 205 |
self.w(u' <%s>%s</%s>\n' % (marker, xml_escape(value), marker)) |