diff libervia/pages/blog/view/page_meta.py @ 1141:02fc28aac2b6

pages: move pagination core from blog to LiberviaPage so it can be reused: 2 new methods are available in LiberviaPage: - getPubsubExtra to generate extra data for bridge when a pubsub get is involved - setPagination to add pagination informations to template_data
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 21:45:59 +0100
parents e1a953512f72
children 29eb15062416
line wrap: on
line diff
--- a/libervia/pages/blog/view/page_meta.py	Fri Jan 11 16:45:01 2019 +0100
+++ b/libervia/pages/blog/view/page_meta.py	Fri Jan 11 21:45:59 2019 +0100
@@ -159,18 +159,10 @@
         profile_connected = True
 
     ## pagination/filtering parameters
-    params = self.getAllPostedData(request, multiple=False)
     if item_id:
         extra = {}
     else:
-        extra = {
-            C.KEY_ORDER_BY: C.ORDER_BY_CREATION,
-            u'rsm_max': unicode(page_max),
-        }
-        if u'after' in params:
-            extra[u'rsm_after'] = params[u'after']
-        elif u'before' in params:
-            extra[u'rsm_before'] = params[u'before']
+        extra = self.getPubsubExtra(request, page_max=page_max)
         tag = data.get('tag')
         if tag:
             extra[u'mam_filter_{}'.format(C.MAM_FILTER_CATEGORY)] = tag
@@ -189,26 +181,14 @@
     target_profile = template_data.get(u'target_profile')
 
     if items:
-        if items.with_rsm and not item_id:
-            last_id = items.rsm_last
-
-            if not items.complete:
-                # we also show the page next button if complete is None because we
-                # can't know where we are in the feed in this case.
-                template_data['older_url'] = self.getParamURL(request, after=last_id)
-            if items.metadata.get("rsm_index", 1) > 0:
-                # We only show previous button if it's not the first page already.
-                # If we have no index, we default to display the button anyway
-                # as we can't know if we are on the first page or not.
-                first_id = items.rsm_first
-                template_data['newer_url']  = self.getParamURL(request, before=first_id)
+        if not item_id:
+            self.setPagination(request, items.metadata)
     else:
         if item_id:
             # if item id has been specified in URL and it's not found,
             # we must return an error
             self.pageError(request, C.HTTP_NOT_FOUND)
 
-
     ## identities ##
     # identities are used to show nice nickname or avatars
     identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities