changeset 1466:cff720e26089

pages (blog/view): activate pagination when a single item is shown: `previous_page_url` and `next_page_url` are set when `item_id` is used. For now, they are both activated even if there is no item before or after, as it would request to make extra request to check it. This may be improved in 0.9 by using internal cache. fix 399
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2021 17:04:22 +0200
parents a410db730301
children d6062cccd4c0
files libervia/pages/blog/view/page_meta.py
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/pages/blog/view/page_meta.py	Thu Sep 30 17:01:20 2021 +0200
+++ b/libervia/pages/blog/view/page_meta.py	Thu Sep 30 17:04:22 2021 +0200
@@ -3,6 +3,7 @@
 import html
 from libervia.server.constants import Const as C
 from twisted.words.protocols.jabber import jid
+from twisted.web import server
 from sat.core.i18n import _, D_
 from sat.tools.common.template import safe
 from sat.tools.common import uri
@@ -142,7 +143,15 @@
             comment_data['items'] = comments['items']
             await appendComments(self, request, comments, profile)
 
-async def getBlogItems(self, request, service, node, item_id, extra, profile):
+async def getBlogItems(
+    self,
+    request: server.Request,
+    service: jid.JID,
+    node: str,
+    item_id,
+    extra: dict,
+    profile: str
+) -> dict:
     try:
         if item_id:
             items_id = [item_id]
@@ -209,7 +218,25 @@
     target_profile = template_data.get('target_profile')
 
     if blog_items:
-        if not item_id:
+        if item_id:
+            template_data["previous_page_url"] = self.getURL(
+                service.full(),
+                node,
+                before=item_id,
+                page_max=1
+            )
+            template_data["next_page_url"] = self.getURL(
+                service.full(),
+                node,
+                after=item_id,
+                page_max=1
+            )
+            blog_items["rsm"] = {
+                "last": item_id,
+                "first": item_id,
+            }
+            blog_items["complete"] = False
+        else:
             self.setPagination(request, blog_items)
     else:
         if item_id: