diff src/server/blog.py @ 454:3ef6ce200c27

server_side: URL query parameter 'max_items' can be used to set the maximal number of blog posts to retrieve
author souliane <souliane@mailoo.org>
date Mon, 26 May 2014 14:25:56 +0200
parents 981ed669d3b3
children bbdc5357dc00
line wrap: on
line diff
--- a/src/server/blog.py	Thu May 22 20:17:10 2014 +0200
+++ b/src/server/blog.py	Mon May 26 14:25:56 2014 +0200
@@ -67,10 +67,14 @@
                     pub_jid = JID(pub_jid_s)
                     d2 = defer.Deferred()
                     item_id = None
+                    try:
+                        max_items = int(request.args['max_items'][0])
+                    except (ValueError, KeyError):
+                        max_items = 10
                     if len(request.postpath) > 1:
                         if request.postpath[1] == 'atom.xml':  # return the atom feed
                             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)
+                            self.host.bridge.getLastGroupBlogsAtom(pub_jid.userhost(), max_items, 'libervia', d2.callback, d2.errback)
                             return
                         try:  # check if the given path is a valid UUID
                             uuid.UUID(request.postpath[1])
@@ -81,7 +85,7 @@
                     if item_id:  # display one message and its comments
                         self.host.bridge.getGroupBlogsWithComments(pub_jid.userhost(), [item_id], 'libervia', d2.callback, d2.errback)
                     else:  # display the last messages without comment
-                        self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), 10, 'libervia', d2.callback, d2.errback)
+                        self.host.bridge.getLastGroupBlogs(pub_jid.userhost(), max_items, 'libervia', d2.callback, d2.errback)
 
                 d1 = defer.Deferred()
                 JID(self.host.bridge.asyncGetParamA('JabberID', 'Connection', 'value', C.SERVER_SECURITY_LIMIT, prof_found, callback=d1.callback, errback=d1.errback))