comparison libervia/web/pages/forums/list/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/forums/list/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3 from libervia.web.server.constants import Const as C
4 from libervia.backend.core.log import getLogger
5 from libervia.backend.core.i18n import _
6 from libervia.backend.tools.common import uri as xmpp_uri
7
8 log = getLogger(__name__)
9 import json
10
11 """forum handling pages"""
12
13 name = "forums"
14 access = C.PAGES_ACCESS_PUBLIC
15 template = "forum/overview.html"
16
17
18 def parse_url(self, request):
19 self.get_path_args(
20 request,
21 ["service", "node", "forum_key"],
22 service="@jid",
23 node="@",
24 forum_key="",
25 )
26
27
28 def add_breadcrumb(self, request, breadcrumbs):
29 # we don't want breadcrumbs here as long as there is no forum discovery
30 # because it will be the landing page for forums activity until then
31 pass
32
33
34 def get_links(self, forums):
35 for forum in forums:
36 try:
37 uri = forum["uri"]
38 except KeyError:
39 pass
40 else:
41 uri = xmpp_uri.parse_xmpp_uri(uri)
42 service = uri["path"]
43 node = uri["node"]
44 forum["http_url"] = self.get_page_by_name("forum_topics").get_url(service, node)
45 if "sub-forums" in forum:
46 get_links(self, forum["sub-forums"])
47
48
49 async def prepare_render(self, request):
50 data = self.get_r_data(request)
51 template_data = request.template_data
52 service, node, key = data["service"], data["node"], data["forum_key"]
53 profile = self.get_profile(request) or C.SERVICE_PROFILE
54
55 try:
56 forums_raw = await self.host.bridge_call(
57 "forums_get", service.full() if service else "", node, key, profile
58 )
59 except Exception as e:
60 log.warning(_("Can't retrieve forums: {msg}").format(msg=e))
61 forums = []
62 else:
63 forums = json.loads(forums_raw)
64 get_links(self, forums)
65
66 template_data["forums"] = forums