annotate libervia/pages/forums/view/page_meta.py @ 1444:7101c51b59ef

Added tag v0.8.0b1 for changeset 3821168b9459
author Goffi <goffi@goffi.org>
date Fri, 18 Jun 2021 16:26:17 +0200
parents eaf36fffcbdb
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1220
diff changeset
2
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
11 name = "forum_view"
1427
eaf36fffcbdb pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents: 1426
diff changeset
12 label = D_("View")
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PUBLIC
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
14 template = "forum/view.html"
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 def parse_url(self, request):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
1427
eaf36fffcbdb pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents: 1426
diff changeset
21 async def prepare_render(self, request):
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
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
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 profile = self.getProfile(request)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
35 type_ = self.getPostedData(request, "type")
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
36 if type_ == "comment":
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
37 service, node, body = self.getPostedData(request, ("service", "node", "body"))
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 if not body:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 except Exception as e:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
46 if "forbidden" in str(e):
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.pageError(request, 401)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 else:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 raise e
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 else:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1173
diff changeset
51 log.warning(_("Unhandled data type: {}").format(type_))