comparison src/pages/common/blog/page_meta.py @ 947:92f0eeb6dc72

pages: cache identities identities in session + get identities for comments in blog
author Goffi <goffi@goffi.org>
date Tue, 23 May 2017 00:06:00 +0200
parents 1375b96f4309
children c20ac29d869f
comparison
equal deleted inserted replaced
946:d076b722ca52 947:92f0eeb6dc72
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 from libervia.server.constants import Const as C 3 from libervia.server.constants import Const as C
4 from twisted.words.protocols.jabber import jid 4 from twisted.words.protocols.jabber import jid
5 from twisted.internet import defer 5 from twisted.internet import defer
6 from sat.tools.common import data_objects 6 from sat.tools.common import data_objects
7 from libervia.server import session_iface
7 from sat.core.i18n import _ 8 from sat.core.i18n import _
8 from sat.core.log import getLogger 9 from sat.core.log import getLogger
9 import urllib 10 import urllib
10 log = getLogger('pages/common/blog') 11 log = getLogger('pages/common/blog')
11 12
45 except IndexError: 46 except IndexError:
46 data['node'] = u'' 47 data['node'] = u''
47 48
48 49
49 @defer.inlineCallbacks 50 @defer.inlineCallbacks
50 def appendComments(self, blog_items, profile): 51 def appendComments(self, blog_items, identities, profile):
51 for blog_item in blog_items: 52 for blog_item in blog_items:
53 if identities is not None:
54 author = blog_item.author_jid
55 if author not in identities:
56 identities[author] = yield self.host.bridge.identityGet(author, profile)
52 for comment_data in blog_item.comments: 57 for comment_data in blog_item.comments:
53 service = comment_data[u'service'] 58 service = comment_data[u'service']
54 node = comment_data[u'node'] 59 node = comment_data[u'node']
55 comments_data = yield self.host.bridge.mbGet( 60 comments_data = yield self.host.bridge.mbGet(
56 service, 61 service,
59 [], 64 [],
60 {}, 65 {},
61 profile) 66 profile)
62 comments = data_objects.BlogItems(comments_data) 67 comments = data_objects.BlogItems(comments_data)
63 blog_item.appendCommentsItems(comments) 68 blog_item.appendCommentsItems(comments)
64 yield appendComments(self, comments, profile) 69 yield appendComments(self, comments, identities, profile)
65 70
66 71
67 @defer.inlineCallbacks 72 @defer.inlineCallbacks
68 def prepare_render(self, request): 73 def prepare_render(self, request):
69 data = self.getRData(request) 74 data = self.getRData(request)
87 self.pageError(request, 401) 92 self.pageError(request, 401)
88 else: 93 else:
89 raise e 94 raise e
90 95
91 items = data_objects.BlogItems(blog_data) 96 items = data_objects.BlogItems(blog_data)
97 template_data = request.template_data
98 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities
92 99
93 if show_comments: 100 if show_comments:
94 yield appendComments(self, items, profile) 101 yield appendComments(self, items, identities, profile)
95 102
96 template_data = request.template_data
97 template_data[u'items'] = items 103 template_data[u'items'] = items
98 template_data[u'allow_commenting'] = u'simple' 104 template_data[u'allow_commenting'] = u'simple'
99 105
100 106
101 @defer.inlineCallbacks 107 @defer.inlineCallbacks