comparison src/pages/common/blog/page_meta.py @ 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 ee243d48100e
children e4c13a995e0b
comparison
equal deleted inserted replaced
931:8a393ae90f8c 932:af6a62e21053
45 except IndexError: 45 except IndexError:
46 data['node'] = u'' 46 data['node'] = u''
47 47
48 48
49 @defer.inlineCallbacks 49 @defer.inlineCallbacks
50 def appendComments(self, blog_items, profile):
51 for blog_item in blog_items:
52 for comment_data in blog_item.comments:
53 service = comment_data[u'service']
54 node = comment_data[u'node']
55 comments_data = yield self.host.bridge.mbGet(
56 service,
57 node,
58 C.NO_LIMIT,
59 [],
60 {},
61 profile)
62 comments = data_objects.BlogItems(comments_data)
63 blog_item.appendCommentsItems(comments)
64 yield appendComments(self, comments, profile)
65
66
67 @defer.inlineCallbacks
50 def prepare_render(self, request): 68 def prepare_render(self, request):
51 data = self.getRData(request) 69 data = self.getRData(request)
52 service, node = data.get(u'service', u''), data.get(u'node', u'') 70 # if the comments are not explicitly hidden, we show them
71 service, node, show_comments = data.get(u'service', u''), data.get(u'node', u''), data.get(u'show_comments', True)
53 profile = self.getProfile(request) 72 profile = self.getProfile(request)
54 if profile is None: 73 if profile is None:
55 profile = C.SERVICE_PROFILE 74 profile = C.SERVICE_PROFILE
56 75
57 try: 76 try:
67 if u"forbidden" in unicode(e): 86 if u"forbidden" in unicode(e):
68 self.pageError(request, 401) 87 self.pageError(request, 401)
69 else: 88 else:
70 raise e 89 raise e
71 90
72 request.template_data[u'items'] = data_objects.BlogItems(blog_data) 91 items = data_objects.BlogItems(blog_data)
92
93 if show_comments:
94 yield appendComments(self, items, profile)
95
96 template_data = request.template_data
97 template_data[u'items'] = items