changeset 1410:80683be8d341

pages: keep `search` query when using pagination
author Goffi <goffi@goffi.org>
date Thu, 22 Apr 2021 18:23:47 +0200
parents 83b477d36725
children 2c3bdba880bb
files libervia/server/pages.py
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/pages.py	Thu Apr 22 18:22:49 2021 +0200
+++ b/libervia/server/pages.py	Thu Apr 22 18:23:47 2021 +0200
@@ -970,6 +970,7 @@
         @param pubsub_data(dict): pubsub metadata
         """
         template_data = request.template_data
+        extra = {}
         try:
             rsm = pubsub_data["rsm"]
             last_id = rsm["last"]
@@ -977,17 +978,23 @@
             # no pagination available
             return
 
+        # if we have a search query, we must keep it
+        search = self.getPostedData(request, 'search', raise_on_missing=False)
+        if search is not None:
+            extra['search'] = search.strip()
+
         if rsm.get("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 = rsm["first"]
-            template_data['previous_page_url'] = self.getParamURL(request,
-                                                                  before=first_id)
+            template_data['previous_page_url'] = self.getParamURL(
+                request, before=first_id, **extra)
         if not pubsub_data["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['next_page_url'] = self.getParamURL(request, after=last_id)
+            template_data['next_page_url'] = self.getParamURL(
+                request, after=last_id, **extra)
 
 
     ## Cache handling ##