changeset 932:af6a62e21053

pages (common/blog): new show_comments variable is used in session data, if True comments are grabbed and chained to items
author Goffi <goffi@goffi.org>
date Mon, 17 Apr 2017 20:43:12 +0200
parents 8a393ae90f8c
children e4c13a995e0b
files src/pages/common/blog/page_meta.py
diffstat 1 files changed, 27 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/pages/common/blog/page_meta.py	Mon Apr 17 20:41:00 2017 +0200
+++ b/src/pages/common/blog/page_meta.py	Mon Apr 17 20:43:12 2017 +0200
@@ -47,9 +47,28 @@
 
 
 @defer.inlineCallbacks
+def appendComments(self, blog_items, profile):
+    for blog_item in blog_items:
+        for comment_data in blog_item.comments:
+            service = comment_data[u'service']
+            node = comment_data[u'node']
+            comments_data = yield self.host.bridge.mbGet(
+                                  service,
+                                  node,
+                                  C.NO_LIMIT,
+                                  [],
+                                  {},
+                                  profile)
+            comments = data_objects.BlogItems(comments_data)
+            blog_item.appendCommentsItems(comments)
+            yield appendComments(self, comments, profile)
+
+
+@defer.inlineCallbacks
 def prepare_render(self, request):
     data = self.getRData(request)
-    service, node = data.get(u'service', u''), data.get(u'node', u'')
+    # if the comments are not explicitly hidden, we show them
+    service, node, show_comments = data.get(u'service', u''), data.get(u'node', u''), data.get(u'show_comments', True)
     profile = self.getProfile(request)
     if profile is None:
         profile = C.SERVICE_PROFILE
@@ -69,4 +88,10 @@
         else:
             raise e
 
-    request.template_data[u'items'] = data_objects.BlogItems(blog_data)
+    items = data_objects.BlogItems(blog_data)
+
+    if show_comments:
+        yield appendComments(self, items, profile)
+
+    template_data = request.template_data
+    template_data[u'items'] = items