comparison libervia/pages/blog/view/page_meta.py @ 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 6fc41f000d24
children 10ccad665d57
comparison
equal deleted inserted replaced
1465:a410db730301 1466:cff720e26089
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 import html 3 import html
4 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
5 from twisted.words.protocols.jabber import jid 5 from twisted.words.protocols.jabber import jid
6 from twisted.web import server
6 from sat.core.i18n import _, D_ 7 from sat.core.i18n import _, D_
7 from sat.tools.common.template import safe 8 from sat.tools.common.template import safe
8 from sat.tools.common import uri 9 from sat.tools.common import uri
9 from sat.tools.common import data_format 10 from sat.tools.common import data_format
10 from sat.tools.common import regex 11 from sat.tools.common import regex
140 141
141 comments = data_format.deserialise(comments_data) 142 comments = data_format.deserialise(comments_data)
142 comment_data['items'] = comments['items'] 143 comment_data['items'] = comments['items']
143 await appendComments(self, request, comments, profile) 144 await appendComments(self, request, comments, profile)
144 145
145 async def getBlogItems(self, request, service, node, item_id, extra, profile): 146 async def getBlogItems(
147 self,
148 request: server.Request,
149 service: jid.JID,
150 node: str,
151 item_id,
152 extra: dict,
153 profile: str
154 ) -> dict:
146 try: 155 try:
147 if item_id: 156 if item_id:
148 items_id = [item_id] 157 items_id = [item_id]
149 else: 158 else:
150 items_id = [] 159 items_id = []
207 if 'node' not in template_data: 216 if 'node' not in template_data:
208 template_data['node'] = node 217 template_data['node'] = node
209 target_profile = template_data.get('target_profile') 218 target_profile = template_data.get('target_profile')
210 219
211 if blog_items: 220 if blog_items:
212 if not item_id: 221 if item_id:
222 template_data["previous_page_url"] = self.getURL(
223 service.full(),
224 node,
225 before=item_id,
226 page_max=1
227 )
228 template_data["next_page_url"] = self.getURL(
229 service.full(),
230 node,
231 after=item_id,
232 page_max=1
233 )
234 blog_items["rsm"] = {
235 "last": item_id,
236 "first": item_id,
237 }
238 blog_items["complete"] = False
239 else:
213 self.setPagination(request, blog_items) 240 self.setPagination(request, blog_items)
214 else: 241 else:
215 if item_id: 242 if item_id:
216 # if item id has been specified in URL and it's not found, 243 # if item id has been specified in URL and it's not found,
217 # we must return an error 244 # we must return an error