Mercurial > libervia-web
comparison libervia_server/blog.py @ 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 | ce5b33f499c5 |
children | 2109d7d30ffc |
comparison
equal
deleted
inserted
replaced
343:b66028d21a1c | 344:d7b98e499935 |
---|---|
22 from twisted.internet import reactor, defer | 22 from twisted.internet import reactor, defer |
23 from twisted.web import server | 23 from twisted.web import server |
24 from twisted.web.resource import Resource | 24 from twisted.web.resource import Resource |
25 from twisted.words.protocols.jabber.jid import JID | 25 from twisted.words.protocols.jabber.jid import JID |
26 from datetime import datetime | 26 from datetime import datetime |
27 from feed import atom | |
27 from constants import Const | 28 from constants import Const |
28 | 29 |
29 | 30 |
30 class MicroBlog(Resource): | 31 class MicroBlog(Resource): |
31 isLeaf = True | 32 isLeaf = True |
58 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" | 59 return MicroBlog.ERROR_TEMPLATE % "Invalid nickname" |
59 else: | 60 else: |
60 def got_jid(pub_jid_s): | 61 def got_jid(pub_jid_s): |
61 pub_jid = JID(pub_jid_s) | 62 pub_jid = JID(pub_jid_s) |
62 d2 = defer.Deferred() | 63 d2 = defer.Deferred() |
63 d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None) | 64 if len(request.postpath) > 1 and request.postpath[1] == 'atom.xml': |
64 self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback) | 65 d2.addCallbacks(self.render_atom_feed, self.render_error_blog, [request], None, [request, prof_found], None) |
66 self.host.bridge.getLastGroupBlogsAtom(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback) | |
67 else: | |
68 d2.addCallbacks(self.render_html_blog, self.render_error_blog, [request, prof_found], None, [request, prof_found], None) | |
69 self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback) | |
65 | 70 |
66 d1 = defer.Deferred() | 71 d1 = defer.Deferred() |
67 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', Const.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback)) | 72 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', Const.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback)) |
68 d1.addCallbacks(got_jid) | 73 d1.addCallbacks(got_jid) |
69 | 74 |
91 'date': _datetime, | 96 'date': _datetime, |
92 'content': body}) | 97 'content': body}) |
93 request.write('</body></html>') | 98 request.write('</body></html>') |
94 request.finish() | 99 request.finish() |
95 | 100 |
101 def render_atom_feed(self, feed, request): | |
102 request.write(feed.encode('utf-8')) | |
103 request.finish() | |
104 | |
96 def render_error_blog(self, error, request, profile): | 105 def render_error_blog(self, error, request, profile): |
97 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") | 106 request.write(MicroBlog.ERROR_TEMPLATE % "Can't access requested data") |
98 request.finish() | 107 request.finish() |