comparison libervia/web/pages/forums/view/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/view/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3
4 from libervia.web.server.constants import Const as C
5 from libervia.backend.core.i18n import _, D_
6 from libervia.backend.core.log import getLogger
7 from libervia.backend.tools.common import data_format
8
9 log = getLogger(__name__)
10
11 name = "forum_view"
12 label = D_("View")
13 access = C.PAGES_ACCESS_PUBLIC
14 template = "forum/view.html"
15
16
17 def parse_url(self, request):
18 self.get_path_args(request, ["service", "node"], 2, service="jid")
19
20
21 async def prepare_render(self, request):
22 data = self.get_r_data(request)
23 data["show_comments"] = False
24 blog_page = self.get_page_by_name("blog_view")
25 request.args[b"before"] = [b""]
26 request.args[b"reverse"] = [b"1"]
27 await blog_page.prepare_render(self, request)
28 request.template_data["login_url"] = self.get_page_redirect_url(request)
29
30
31 async def on_data_post(self, request):
32 profile = self.get_profile(request)
33 if profile is None:
34 self.page_error(request, C.HTTP_FORBIDDEN)
35 type_ = self.get_posted_data(request, "type")
36 if type_ == "comment":
37 service, node, body = self.get_posted_data(request, ("service", "node", "body"))
38
39 if not body:
40 self.page_error(request, C.HTTP_BAD_REQUEST)
41 mb_data = {"content_rich": body}
42 try:
43 await self.host.bridge_call(
44 "mb_send", service, node, data_format.serialise(mb_data), profile)
45 except Exception as e:
46 if "forbidden" in str(e):
47 self.page_error(request, 401)
48 else:
49 raise e
50 else:
51 log.warning(_("Unhandled data type: {}").format(type_))