Mercurial > libervia-web
annotate libervia/pages/forums/view/page_meta.py @ 1427:eaf36fffcbdb
pages (forums): better breadcrumbs
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 19:05:16 +0200 |
parents | 4cf2b73e63aa |
children | 106bae41f5c8 |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1058 | 3 |
4 from libervia.server.constants import Const as C | |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1426
diff
changeset
|
5 from sat.core.i18n import _, D_ |
1058 | 6 from sat.core.log import getLogger |
1220
afb40966cd0a
pages (forums/view): fixed microblog data serialisation when posting
Goffi <goffi@goffi.org>
parents:
1219
diff
changeset
|
7 from sat.tools.common import data_format |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
8 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
9 log = getLogger(__name__) |
1058 | 10 |
1216 | 11 name = "forum_view" |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1426
diff
changeset
|
12 label = D_("View") |
1058 | 13 access = C.PAGES_ACCESS_PUBLIC |
1216 | 14 template = "forum/view.html" |
1058 | 15 |
16 | |
17 def parse_url(self, request): | |
1216 | 18 self.getPathArgs(request, ["service", "node"], 2, service="jid") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
19 |
1058 | 20 |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1426
diff
changeset
|
21 async def prepare_render(self, request): |
1058 | 22 data = self.getRData(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
23 data["show_comments"] = False |
1216 | 24 blog_page = self.getPageByName("blog_view") |
1219
0f0c36992f3c
pages (blog/view, forums/view): fixed encoding of request.args following Python3 port
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
25 request.args[b"before"] = [b""] |
0f0c36992f3c
pages (blog/view, forums/view): fixed encoding of request.args following Python3 port
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
26 request.args[b"reverse"] = [b"1"] |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1426
diff
changeset
|
27 await blog_page.prepare_render(self, request) |
1216 | 28 request.template_data["login_url"] = self.getPageRedirectURL(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
29 |
1058 | 30 |
1426
4cf2b73e63aa
pages (forums/view): use rich content to post a reply
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
31 async def on_data_post(self, request): |
1058 | 32 profile = self.getProfile(request) |
33 if profile is None: | |
1173
0f37b65fe7c2
server: replaced wrong usage of C.HTTP_UNAUTHORIZED by C.HTTP_FORBIDDEN
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
34 self.pageError(request, C.HTTP_FORBIDDEN) |
1216 | 35 type_ = self.getPostedData(request, "type") |
36 if type_ == "comment": | |
37 service, node, body = self.getPostedData(request, ("service", "node", "body")) | |
1058 | 38 |
39 if not body: | |
40 self.pageError(request, C.HTTP_BAD_REQUEST) | |
1426
4cf2b73e63aa
pages (forums/view): use rich content to post a reply
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
41 mb_data = {"content_rich": body} |
1058 | 42 try: |
1426
4cf2b73e63aa
pages (forums/view): use rich content to post a reply
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
43 await self.host.bridgeCall( |
1220
afb40966cd0a
pages (forums/view): fixed microblog data serialisation when posting
Goffi <goffi@goffi.org>
parents:
1219
diff
changeset
|
44 "mbSend", service, node, data_format.serialise(mb_data), profile) |
1058 | 45 except Exception as e: |
1216 | 46 if "forbidden" in str(e): |
1058 | 47 self.pageError(request, 401) |
48 else: | |
49 raise e | |
50 else: | |
1216 | 51 log.warning(_("Unhandled data type: {}").format(type_)) |