comparison libervia/web/pages/blog/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/blog/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3 from libervia.backend.core.i18n import _
4 from libervia.web.server.constants import Const as C
5 from twisted.words.protocols.jabber import jid
6 from twisted.internet import defer
7 from libervia.web.server import session_iface
8 from libervia.backend.tools.common import data_format
9 from libervia.backend.core.log import getLogger
10
11 log = getLogger(__name__)
12
13 name = "blog"
14 access = C.PAGES_ACCESS_PUBLIC
15 template = "blog/discover.html"
16
17
18 async def prepare_render(self, request):
19 profile = self.get_profile(request)
20 template_data = request.template_data
21 if profile is not None:
22 __, entities_own, entities_roster = await self.host.bridge_call(
23 "disco_find_by_features",
24 [],
25 [("pubsub", "pep")],
26 True,
27 False,
28 True,
29 True,
30 True,
31 profile,
32 )
33 entities = template_data["disco_entities"] = (
34 list(entities_own.keys()) + list(entities_roster.keys())
35 )
36 entities_url = template_data["entities_url"] = {}
37 identities = self.host.get_session_data(
38 request, session_iface.IWebSession
39 ).identities
40 d_list = {}
41 for entity_jid_s in entities:
42 entities_url[entity_jid_s] = self.get_page_by_name("blog_view").get_url(
43 entity_jid_s
44 )
45 if entity_jid_s not in identities:
46 d_list[entity_jid_s] = self.host.bridge_call(
47 "identity_get",
48 entity_jid_s,
49 [],
50 True,
51 profile)
52 identities_data = await defer.DeferredList(d_list.values())
53 entities_idx = list(d_list.keys())
54 for idx, (success, identity_raw) in enumerate(identities_data):
55 entity_jid_s = entities_idx[idx]
56 if not success:
57 log.warning(_("Can't retrieve identity of {entity}")
58 .format(entity=entity_jid_s))
59 else:
60 identities[entity_jid_s] = data_format.deserialise(identity_raw)
61
62 template_data["url_blog_edit"] = self.get_sub_page_url(request, "blog_edit")
63
64
65 def on_data_post(self, request):
66 jid_str = self.get_posted_data(request, "jid")
67 try:
68 jid_ = jid.JID(jid_str)
69 except RuntimeError:
70 self.page_error(request, C.HTTP_BAD_REQUEST)
71 url = self.get_page_by_name("blog_view").get_url(jid_.full())
72 self.http_redirect(request, url)