changeset 344:d7b98e499935

server_side: Atom feed for blogposts is accessible from <host>/blog/<user>/atom.xml
author souliane <souliane@mailoo.org>
date Wed, 22 Jan 2014 17:07:50 +0100
parents b66028d21a1c
children 2109d7d30ffc
files libervia_server/blog.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libervia_server/blog.py	Sat Jan 18 11:24:52 2014 +0100
+++ b/libervia_server/blog.py	Wed Jan 22 17:07:50 2014 +0100
@@ -24,6 +24,7 @@
 from twisted.web.resource import Resource
 from twisted.words.protocols.jabber.jid import JID
 from datetime import datetime
+from feed import atom
 from constants import Const
 
 
@@ -60,8 +61,12 @@
                 def got_jid(pub_jid_s):
                     pub_jid = JID(pub_jid_s)
                     d2 = defer.Deferred()
-                    d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None)
-                    self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback)
+                    if len(request.postpath) > 1 and request.postpath[1] == 'atom.xml':
+                        d2.addCallbacks(self.render_atom_feed, self.render_error_blog, [request], None, [request, prof_found], None)
+                        self.host.bridge.getLastGroupBlogsAtom(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback)
+                    else:
+                        d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None)
+                        self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback)
 
                 d1 = defer.Deferred()
                 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', Const.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback))
@@ -93,6 +98,10 @@
         request.write('</body></html>')
         request.finish()
 
+    def render_atom_feed(self, feed, request):
+        request.write(feed.encode('utf-8'))
+        request.finish()
+
     def render_error_blog(self, error, request, profile):
         request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data")
         request.finish()