[IMP] website_blog: group the get_discussion in one request(get_discussionS), that will avoid to make one request by paragraph in blog.

This commit is contained in:
Jeremy Kersten
2014-07-29 12:05:50 +02:00
parent 7b4846afd7
commit db20a45186
2 changed files with 31 additions and 10 deletions
+8 -1
View File
@@ -244,7 +244,6 @@ class WebsiteBlog(http.Controller):
cr, uid, context = request.cr, request.uid, request.context
blog_post = request.registry['blog.post']
partner_obj = request.registry['res.partner']
thread_obj = request.registry['mail.thread']
if uid != request.website.user_id.id:
partner_ids = [user.partner_id.id]
@@ -343,6 +342,14 @@ class WebsiteBlog(http.Controller):
return ids
return self._get_discussion_detail(ids, publish, **post)
@http.route('/blogpost/get_discussions/', type='json', auth="public", website=True)
def discussions(self, post_id=0, paths=None, count=False, **post):
ret = []
for path in paths:
result = self.discussion(post_id=post_id, path=path, count=count, **post)
ret.append({"path": path, "val": result})
return ret
@http.route('/blogpost/change_background', type='json', auth="public", website=True)
def change_bg(self, post_id=0, image=None, **post):
if not post_id:
@@ -25,9 +25,8 @@
$('<div id="discussions_wrapper"></div>').insertAfter($('#blog_content'));
}
// Attach a discussion to each paragraph.
$(self.settings.content).each(function(i) {
self.discussion_handler(i, $(this));
});
self.discussions_handler(self.settings.content);
// Hide the discussion.
$('html').click(function(event) {
if($(event.target).parents('#discussions_wrapper, .main-discussion-link-wrp').length === 0) {
@@ -54,14 +53,29 @@
'count': comment_count, //if true only get length of total comment, display on discussion thread.
})
},
discussion_handler : function(i, node) {
prepare_multi_data : function(identifiers, comment_count) {
var self = this;
var identifier = node.attr('data-chatter-id');
if (identifier) {
self.prepare_data(identifier, true).then( function (data) {
self.prepare_discuss_link(data, identifier, node);
return openerp.jsonRpc("/blogpost/get_discussions/", 'call', {
'post_id': self.settings.post_id,
'paths': identifiers,
'count': comment_count, //if true only get length of total comment, display on discussion thread.
})
},
discussions_handler: function() {
var self = this;
var node_by_id = {};
$(self.settings.content).each(function(i) {
var node = $(this);
var identifier = node.attr('data-chatter-id');
if (identifier) {
node_by_id[identifier] = node;
}
});
self.prepare_multi_data(_.keys(node_by_id), true).then( function (multi_data) {
_.forEach(multi_data, function(data) {
self.prepare_discuss_link(data.val, data.path, node_by_id[data.path]);
});
}
});
},
prepare_discuss_link : function(data, identifier, node) {
var self = this;