Mercurial > libervia-web
comparison libervia/pages/blog/view/page_meta.py @ 1483:595e7fef41f3
merge bookmark @
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 12 Nov 2021 17:48:30 +0100 |
parents | 907f519faaf0 10ccad665d57 |
children | 3002ea1d6ae9 |
comparison
equal
deleted
inserted
replaced
1454:fc91b78b71db | 1483:595e7fef41f3 |
---|---|
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 |
142 | 143 |
143 comments = data_format.deserialise(comments_data) | 144 comments = data_format.deserialise(comments_data) |
144 comment_data['items'] = comments['items'] | 145 comment_data['items'] = comments['items'] |
145 await appendComments(self, request, comments, profile) | 146 await appendComments(self, request, comments, profile) |
146 | 147 |
147 async def getBlogItems(self, request, service, node, item_id, extra, profile): | 148 async def getBlogItems( |
149 self, | |
150 request: server.Request, | |
151 service: jid.JID, | |
152 node: str, | |
153 item_id, | |
154 extra: dict, | |
155 profile: str | |
156 ) -> dict: | |
148 try: | 157 try: |
149 if item_id: | 158 if item_id: |
150 items_id = [item_id] | 159 items_id = [item_id] |
151 else: | 160 else: |
152 items_id = [] | 161 items_id = [] |
209 if 'node' not in template_data: | 218 if 'node' not in template_data: |
210 template_data['node'] = node | 219 template_data['node'] = node |
211 target_profile = template_data.get('target_profile') | 220 target_profile = template_data.get('target_profile') |
212 | 221 |
213 if blog_items: | 222 if blog_items: |
214 if not item_id: | 223 if item_id: |
224 template_data["previous_page_url"] = self.getURL( | |
225 service.full(), | |
226 node, | |
227 before=item_id, | |
228 page_max=1 | |
229 ) | |
230 template_data["next_page_url"] = self.getURL( | |
231 service.full(), | |
232 node, | |
233 after=item_id, | |
234 page_max=1 | |
235 ) | |
236 blog_items["rsm"] = { | |
237 "last": item_id, | |
238 "first": item_id, | |
239 } | |
240 blog_items["complete"] = False | |
241 else: | |
215 self.setPagination(request, blog_items) | 242 self.setPagination(request, blog_items) |
216 else: | 243 else: |
217 if item_id: | 244 if item_id: |
218 # if item id has been specified in URL and it's not found, | 245 # if item id has been specified in URL and it's not found, |
219 # we must return an error | 246 # we must return an error |
285 uri_args = {'path': service.full()} | 312 uri_args = {'path': service.full()} |
286 if node: | 313 if node: |
287 uri_args['node'] = node | 314 uri_args['node'] = node |
288 if item_id: | 315 if item_id: |
289 uri_args['item'] = item_id | 316 uri_args['item'] = item_id |
290 template_data['xmpp_uri'] = uri.buildXMPPUri('pubsub', subtype='microblog', **uri_args) | 317 template_data['xmpp_uri'] = uri.buildXMPPUri( |
318 'pubsub', subtype='microblog', **uri_args | |
319 ) | |
291 | 320 |
292 | 321 |
293 async def on_data_post(self, request): | 322 async def on_data_post(self, request): |
294 profile = self.getProfile(request) | 323 profile = self.getProfile(request) |
295 if profile is None: | 324 if profile is None: |
298 if type_ == 'comment': | 327 if type_ == 'comment': |
299 service, node, body = self.getPostedData(request, ('service', 'node', 'body')) | 328 service, node, body = self.getPostedData(request, ('service', 'node', 'body')) |
300 | 329 |
301 if not body: | 330 if not body: |
302 self.pageError(request, C.HTTP_BAD_REQUEST) | 331 self.pageError(request, C.HTTP_BAD_REQUEST) |
303 comment_data = {"content": body} | 332 comment_data = {"content_rich": body} |
304 try: | 333 try: |
305 await self.host.bridgeCall('mbSend', | 334 await self.host.bridgeCall('mbSend', |
306 service, | 335 service, |
307 node, | 336 node, |
308 data_format.serialise(comment_data), | 337 data_format.serialise(comment_data), |