Mercurial > libervia-web
annotate libervia/pages/forums/view/page_meta.py @ 1247:a6c7f07f1e4d
tasks: implicit tasks + Brython task:
- implicit tasks are tasks launched for every site.
- a first one is made for Brython: it will install Brython and copy suitable files and set
template data if Brython code is written in page `_browser` subdirectory.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Apr 2020 22:07:18 +0200 |
parents | f511f8fbbf8a |
children | 4cf2b73e63aa |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1058 | 3 |
4 from libervia.server.constants import Const as C | |
5 from twisted.internet import defer | |
6 from sat.core.i18n import _ | |
7 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
|
8 from sat.tools.common import data_format |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
9 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
10 log = getLogger(__name__) |
1058 | 11 |
1216 | 12 name = "forum_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 |
21 @defer.inlineCallbacks | |
22 def prepare_render(self, request): | |
23 data = self.getRData(request) | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
24 data["show_comments"] = False |
1216 | 25 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
|
26 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
|
27 request.args[b"reverse"] = [b"1"] |
1058 | 28 yield blog_page.prepare_render(self, request) |
1216 | 29 request.template_data["login_url"] = self.getPageRedirectURL(request) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
30 |
1058 | 31 |
32 @defer.inlineCallbacks | |
33 def on_data_post(self, request): | |
34 profile = self.getProfile(request) | |
35 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
|
36 self.pageError(request, C.HTTP_FORBIDDEN) |
1216 | 37 type_ = self.getPostedData(request, "type") |
38 if type_ == "comment": | |
39 service, node, body = self.getPostedData(request, ("service", "node", "body")) | |
1058 | 40 |
41 if not body: | |
42 self.pageError(request, C.HTTP_BAD_REQUEST) | |
1216 | 43 mb_data = {"content": body} |
1058 | 44 try: |
1220
afb40966cd0a
pages (forums/view): fixed microblog data serialisation when posting
Goffi <goffi@goffi.org>
parents:
1219
diff
changeset
|
45 yield self.host.bridgeCall( |
afb40966cd0a
pages (forums/view): fixed microblog data serialisation when posting
Goffi <goffi@goffi.org>
parents:
1219
diff
changeset
|
46 "mbSend", service, node, data_format.serialise(mb_data), profile) |
1058 | 47 except Exception as e: |
1216 | 48 if "forbidden" in str(e): |
1058 | 49 self.pageError(request, 401) |
50 else: | |
51 raise e | |
52 else: | |
1216 | 53 log.warning(_("Unhandled data type: {}").format(type_)) |