diff 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
line wrap: on
line diff
--- a/src/pages/common/blog/page_meta.py	Sun May 21 16:00:55 2017 +0200
+++ b/src/pages/common/blog/page_meta.py	Tue May 23 00:06:00 2017 +0200
@@ -4,6 +4,7 @@
 from twisted.words.protocols.jabber import jid
 from twisted.internet import defer
 from sat.tools.common import data_objects
+from libervia.server import session_iface
 from sat.core.i18n import _
 from sat.core.log import getLogger
 import urllib
@@ -47,8 +48,12 @@
 
 
 @defer.inlineCallbacks
-def appendComments(self, blog_items, profile):
+def appendComments(self, blog_items, identities, profile):
     for blog_item in blog_items:
+        if identities is not None:
+            author = blog_item.author_jid
+            if author not in identities:
+                identities[author] = yield self.host.bridge.identityGet(author, profile)
         for comment_data in blog_item.comments:
             service = comment_data[u'service']
             node = comment_data[u'node']
@@ -61,7 +66,7 @@
                                   profile)
             comments = data_objects.BlogItems(comments_data)
             blog_item.appendCommentsItems(comments)
-            yield appendComments(self, comments, profile)
+            yield appendComments(self, comments, identities, profile)
 
 
 @defer.inlineCallbacks
@@ -89,11 +94,12 @@
             raise e
 
     items = data_objects.BlogItems(blog_data)
+    template_data = request.template_data
+    identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities
 
     if show_comments:
-        yield appendComments(self, items, profile)
+        yield appendComments(self, items, identities, profile)
 
-    template_data = request.template_data
     template_data[u'items'] = items
     template_data[u'allow_commenting'] = u'simple'