# HG changeset patch # User Goffi # Date 1515791073 -3600 # Node ID fe08a5c95b27612a1fb53e51cbe8af3e59f2caf0 # Parent 4de970de87d713839ac57a9af317c64031a32d97 pages (blog): added pagination using RSM and blog now fill older_url and newer_url in template_data diff -r 4de970de87d7 -r fe08a5c95b27 src/pages/common/blog/page_meta.py --- a/src/pages/common/blog/page_meta.py Fri Jan 12 22:04:30 2018 +0100 +++ b/src/pages/common/blog/page_meta.py Fri Jan 12 22:04:33 2018 +0100 @@ -76,6 +76,25 @@ blog_item.appendCommentsItems(comments) yield appendComments(self, comments, identities, profile) +@defer.inlineCallbacks +def getBlogData(self, request, service, node, extra, profile): + try: + blog_data = yield self.host.bridge.mbGet( + service.userhost(), + node, + C.NO_LIMIT, + [], + extra, + profile) + except Exception as e: + # FIXME: need a better way to test errors in bridge errback + if u"forbidden" in unicode(e): + self.pageError(request, 401) + else: + raise e + + items = data_objects.BlogItems(blog_data) + defer.returnValue((blog_data, items)) @defer.inlineCallbacks def prepare_render(self, request): @@ -86,23 +105,29 @@ if profile is None: profile = C.SERVICE_PROFILE - try: - blog_data = yield self.host.bridge.mbGet( - service.userhost(), - node, - 10, - [], - {}, - profile) - except Exception as e: - # FIXME: need a better way to test errors in bridge errback - if u"forbidden" in unicode(e): - self.pageError(request, 401) - else: - raise e + params = self.getAllPostedData(request, multiple=False) + extra = {u'rsm_max': u'10'} + if u'after' in params: + extra[u'rsm_after'] = params[u'after'] + elif u'before' in params: + extra[u'rsm_before'] = params[u'before'] - items = data_objects.BlogItems(blog_data) + blog_data, items = yield getBlogData(self, request, service, node, extra, profile) template_data = request.template_data + if items: + last_id = items[-1].id + template_data['older_url'] = self.getParamURL(request, after=last_id) + if u'before' in params or u'after' in params: + first_id = items[0].id + template_data['newer_url'] = self.getParamURL(request, before=first_id) + else: + # no items, we have requested items before last post, or blog is empty + extra = {u'rsm_max': u'10'} + blog_data, items = yield getBlogData(self, request, service, node, extra, profile) + if items: + last_id = items[-1].id + template_data['older_url'] = self.getParamURL(request, after=last_id) + identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities if show_comments: