Mercurial > libervia-web
view libervia/web/pages/forums/list/page_meta.py @ 1574:4ab4bc3ae462
browser: new `tools` module with a first method to detect touch devices
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 22 Nov 2023 16:31:36 +0100 |
parents | eb00d593801d |
children |
line wrap: on
line source
#!/usr/bin/env python3 from libervia.web.server.constants import Const as C from libervia.backend.core.log import getLogger from libervia.backend.core.i18n import _ from libervia.backend.tools.common import uri as xmpp_uri log = getLogger(__name__) import json """forum handling pages""" name = "forums" access = C.PAGES_ACCESS_PUBLIC template = "forum/overview.html" def parse_url(self, request): self.get_path_args( request, ["service", "node", "forum_key"], service="@jid", node="@", forum_key="", ) def add_breadcrumb(self, request, breadcrumbs): # we don't want breadcrumbs here as long as there is no forum discovery # because it will be the landing page for forums activity until then pass def get_links(self, forums): for forum in forums: try: uri = forum["uri"] except KeyError: pass else: uri = xmpp_uri.parse_xmpp_uri(uri) service = uri["path"] node = uri["node"] forum["http_url"] = self.get_page_by_name("forum_topics").get_url(service, node) if "sub-forums" in forum: get_links(self, forum["sub-forums"]) async def prepare_render(self, request): data = self.get_r_data(request) template_data = request.template_data service, node, key = data["service"], data["node"], data["forum_key"] profile = self.get_profile(request) or C.SERVICE_PROFILE try: forums_raw = await self.host.bridge_call( "forums_get", service.full() if service else "", node, key, profile ) except Exception as e: log.warning(_("Can't retrieve forums: {msg}").format(msg=e)) forums = [] else: forums = json.loads(forums_raw) get_links(self, forums) template_data["forums"] = forums