Mercurial > libervia-web
comparison src/pages/common/blog/page_meta.py @ 1011:fe08a5c95b27
pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 12 Jan 2018 22:04:33 +0100 |
parents | d821c112e656 |
children | fc1c913cc9d1 |
comparison
equal
deleted
inserted
replaced
1010:4de970de87d7 | 1011:fe08a5c95b27 |
---|---|
74 | 74 |
75 comments = data_objects.BlogItems(comments_data) | 75 comments = data_objects.BlogItems(comments_data) |
76 blog_item.appendCommentsItems(comments) | 76 blog_item.appendCommentsItems(comments) |
77 yield appendComments(self, comments, identities, profile) | 77 yield appendComments(self, comments, identities, profile) |
78 | 78 |
79 @defer.inlineCallbacks | |
80 def getBlogData(self, request, service, node, extra, profile): | |
81 try: | |
82 blog_data = yield self.host.bridge.mbGet( | |
83 service.userhost(), | |
84 node, | |
85 C.NO_LIMIT, | |
86 [], | |
87 extra, | |
88 profile) | |
89 except Exception as e: | |
90 # FIXME: need a better way to test errors in bridge errback | |
91 if u"forbidden" in unicode(e): | |
92 self.pageError(request, 401) | |
93 else: | |
94 raise e | |
95 | |
96 items = data_objects.BlogItems(blog_data) | |
97 defer.returnValue((blog_data, items)) | |
79 | 98 |
80 @defer.inlineCallbacks | 99 @defer.inlineCallbacks |
81 def prepare_render(self, request): | 100 def prepare_render(self, request): |
82 data = self.getRData(request) | 101 data = self.getRData(request) |
83 # if the comments are not explicitly hidden, we show them | 102 # if the comments are not explicitly hidden, we show them |
84 service, node, show_comments = data.get(u'service', u''), data.get(u'node', u''), data.get(u'show_comments', True) | 103 service, node, show_comments = data.get(u'service', u''), data.get(u'node', u''), data.get(u'show_comments', True) |
85 profile = self.getProfile(request) | 104 profile = self.getProfile(request) |
86 if profile is None: | 105 if profile is None: |
87 profile = C.SERVICE_PROFILE | 106 profile = C.SERVICE_PROFILE |
88 | 107 |
89 try: | 108 params = self.getAllPostedData(request, multiple=False) |
90 blog_data = yield self.host.bridge.mbGet( | 109 extra = {u'rsm_max': u'10'} |
91 service.userhost(), | 110 if u'after' in params: |
92 node, | 111 extra[u'rsm_after'] = params[u'after'] |
93 10, | 112 elif u'before' in params: |
94 [], | 113 extra[u'rsm_before'] = params[u'before'] |
95 {}, | |
96 profile) | |
97 except Exception as e: | |
98 # FIXME: need a better way to test errors in bridge errback | |
99 if u"forbidden" in unicode(e): | |
100 self.pageError(request, 401) | |
101 else: | |
102 raise e | |
103 | 114 |
104 items = data_objects.BlogItems(blog_data) | 115 blog_data, items = yield getBlogData(self, request, service, node, extra, profile) |
105 template_data = request.template_data | 116 template_data = request.template_data |
117 if items: | |
118 last_id = items[-1].id | |
119 template_data['older_url'] = self.getParamURL(request, after=last_id) | |
120 if u'before' in params or u'after' in params: | |
121 first_id = items[0].id | |
122 template_data['newer_url'] = self.getParamURL(request, before=first_id) | |
123 else: | |
124 # no items, we have requested items before last post, or blog is empty | |
125 extra = {u'rsm_max': u'10'} | |
126 blog_data, items = yield getBlogData(self, request, service, node, extra, profile) | |
127 if items: | |
128 last_id = items[-1].id | |
129 template_data['older_url'] = self.getParamURL(request, after=last_id) | |
130 | |
106 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities | 131 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities |
107 | 132 |
108 if show_comments: | 133 if show_comments: |
109 yield appendComments(self, items, identities, profile) | 134 yield appendComments(self, items, identities, profile) |
110 | 135 |