Mercurial > libervia-backend
changeset 892:58107179cd97
plugin groupblog: added a convenient bridge method getGroupBlogsWithComments
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 28 Feb 2014 11:19:08 +0100 |
parents | a7b2aacf22ac |
children | 308a96bc7c1b |
files | src/plugins/plugin_misc_groupblog.py |
diffstat | 1 files changed, 31 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py Tue Feb 25 17:49:15 2014 +0100 +++ b/src/plugins/plugin_misc_groupblog.py Fri Feb 28 11:19:08 2014 +0100 @@ -106,6 +106,11 @@ method=self.getGroupBlogs, async=True) + host.bridge.addMethod("getGroupBlogsWithComments", ".plugin", + in_sign='sass', out_sign='a(a{ss}aa{ss})', + method=self.getGroupBlogsWithComments, + async=True) + host.bridge.addMethod("getLastGroupBlogs", ".plugin", in_sign='sis', out_sign='aa{ss}', method=self.getLastGroupBlogs, @@ -541,6 +546,32 @@ """ return self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) + def getGroupBlogsWithComments(self, pub_jid_s, item_ids=None, profile_key='@NONE@'): + """Get the published microblogs of the specified IDs and their comments. If + item_ids is None, returns the last published microblogs and their comments. + @param pub_jid_s: jid of the publisher + @param item_ids: list of microblogs items IDs + @param profile_key: profile key + @return: list of couple (microblog data, list of microblog data) + """ + def get_comments(data): + d_list = [] + for entry in data: + if entry.get('comments', False): + d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], profile_key=profile_key) + d.addCallback(lambda data: (entry, data)) + d_list.append(d) + else: + d_list.append(defer.succeed((entry, []))) + deferred_list = defer.DeferredList(d_list) + deferred_list.addCallback(lambda result: [value for (success, value) in result if success]) + return deferred_list + + d = self.__getGroupBlogs(pub_jid_s, item_ids=item_ids, profile_key=profile_key) + d.addCallback(get_comments) + return d + + def getLastGroupBlogs(self, pub_jid_s, max_items=10, profile_key='@NONE@'): """Get the last published microblogs @param pub_jid_s: jid of the publisher