# HG changeset patch # User Goffi # Date 1619888716 -7200 # Node ID eaf36fffcbdb414ea6cb77317e76ad5ea7f2c8c0 # Parent 4cf2b73e63aabb4be61e7507149b13f76be6d707 pages (forums): better breadcrumbs diff -r 4cf2b73e63aa -r eaf36fffcbdb libervia/pages/forums/list/page_meta.py --- a/libervia/pages/forums/list/page_meta.py Sat May 01 19:05:16 2021 +0200 +++ b/libervia/pages/forums/list/page_meta.py Sat May 01 19:05:16 2021 +0200 @@ -1,8 +1,6 @@ #!/usr/bin/env python3 - from libervia.server.constants import Const as C -from twisted.internet import defer from sat.core.log import getLogger from sat.core.i18n import _ from sat.tools.common import uri as xmpp_uri @@ -27,6 +25,12 @@ ) +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 getLinks(self, forums): for forum in forums: try: @@ -42,15 +46,14 @@ getLinks(self, forum["sub-forums"]) -@defer.inlineCallbacks -def prepare_render(self, request): +async def prepare_render(self, request): data = self.getRData(request) template_data = request.template_data service, node, key = data["service"], data["node"], data["forum_key"] profile = self.getProfile(request) or C.SERVICE_PROFILE try: - forums_raw = yield self.host.bridgeCall( + forums_raw = await self.host.bridgeCall( "forumsGet", service.full() if service else "", node, key, profile ) except Exception as e: diff -r 4cf2b73e63aa -r eaf36fffcbdb libervia/pages/forums/page_meta.py --- a/libervia/pages/forums/page_meta.py Sat May 01 19:05:16 2021 +0200 +++ b/libervia/pages/forums/page_meta.py Sat May 01 19:05:16 2021 +0200 @@ -0,0 +1,3 @@ + +def prepare_render(self, request): + self.pageRedirect("forums", request, skip_parse_url=False) diff -r 4cf2b73e63aa -r eaf36fffcbdb libervia/pages/forums/topics/page_meta.py --- a/libervia/pages/forums/topics/page_meta.py Sat May 01 19:05:16 2021 +0200 +++ b/libervia/pages/forums/topics/page_meta.py Sat May 01 19:05:16 2021 +0200 @@ -2,8 +2,7 @@ from libervia.server.constants import Const as C -from twisted.internet import defer -from sat.core.i18n import _ +from sat.core.i18n import _, D_ from sat.core.log import getLogger from sat.tools.common import uri as xmpp_uri from sat.tools.common import data_format @@ -12,6 +11,7 @@ log = getLogger(__name__) name = "forum_topics" +label = D_("Forum Topics") access = C.PAGES_ACCESS_PUBLIC template = "forum/view_topics.html" @@ -20,14 +20,21 @@ self.getPathArgs(request, ["service", "node"], 2, service="jid") -@defer.inlineCallbacks -def prepare_render(self, request): +def add_breadcrumb(self, request, breadcrumbs): + data = self.getRData(request) + breadcrumbs.append({ + "label": label, + "url": self.getURL(data["service"].full(), data["node"]) + }) + + +async def prepare_render(self, request): profile = self.getProfile(request) or C.SERVICE_PROFILE data = self.getRData(request) service, node = data["service"], data["node"] request.template_data.update({"service": service, "node": node}) template_data = request.template_data - topics, metadata = yield self.host.bridgeCall( + topics, metadata = await self.host.bridgeCall( "forumTopicsGet", service.full(), node, {}, profile ) identities = self.host.getSessionData( @@ -40,7 +47,7 @@ parsed_uri["path"], parsed_uri["node"] ) if author not in identities: - id_raw = yield self.host.bridgeCall( + id_raw = await self.host.bridgeCall( "identityGet", author, [], True, profile ) identities[topic["author"]] = data_format.deserialise(id_raw) @@ -49,8 +56,7 @@ template_data["url_topic_new"] = self.getSubPageURL(request, "forum_topic_new") -@defer.inlineCallbacks -def on_data_post(self, request): +async def on_data_post(self, request): profile = self.getProfile(request) if profile is None: self.pageError(request, C.HTTP_FORBIDDEN) @@ -64,7 +70,7 @@ self.pageError(request, C.HTTP_BAD_REQUEST) topic_data = {"title": title, "content": body} try: - yield self.host.bridgeCall( + await self.host.bridgeCall( "forumTopicCreate", service, node, topic_data, profile ) except Exception as e: diff -r 4cf2b73e63aa -r eaf36fffcbdb libervia/pages/forums/view/page_meta.py --- a/libervia/pages/forums/view/page_meta.py Sat May 01 19:05:16 2021 +0200 +++ b/libervia/pages/forums/view/page_meta.py Sat May 01 19:05:16 2021 +0200 @@ -2,14 +2,14 @@ from libervia.server.constants import Const as C -from twisted.internet import defer -from sat.core.i18n import _ +from sat.core.i18n import _, D_ from sat.core.log import getLogger from sat.tools.common import data_format log = getLogger(__name__) name = "forum_view" +label = D_("View") access = C.PAGES_ACCESS_PUBLIC template = "forum/view.html" @@ -18,14 +18,13 @@ self.getPathArgs(request, ["service", "node"], 2, service="jid") -@defer.inlineCallbacks -def prepare_render(self, request): +async def prepare_render(self, request): data = self.getRData(request) data["show_comments"] = False blog_page = self.getPageByName("blog_view") request.args[b"before"] = [b""] request.args[b"reverse"] = [b"1"] - yield blog_page.prepare_render(self, request) + await blog_page.prepare_render(self, request) request.template_data["login_url"] = self.getPageRedirectURL(request)