Mercurial > libervia-web
annotate libervia/pages/forums/view/page_meta.py @ 1216:b2d067339de3
python 3 port:
/!\ Python 3.6+ is now needed to use libervia
/!\ instability may occur and features may not be working anymore, this will improve with time
/!\ TxJSONRPC dependency has been removed
The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs
for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog,
JSON RPC related code).
Adapted code to work without `html` and `themes` dirs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:12:31 +0200 |
parents | 0f37b65fe7c2 |
children | 0f0c36992f3c |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1058 | 2 # -*- coding: utf-8 -*- |
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 | |
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" |
1058 | 12 access = C.PAGES_ACCESS_PUBLIC |
1216 | 13 template = "forum/view.html" |
1058 | 14 |
15 | |
16 def parse_url(self, request): | |
1216 | 17 self.getPathArgs(request, ["service", "node"], 2, service="jid") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
18 |
1058 | 19 |
20 @defer.inlineCallbacks | |
21 def prepare_render(self, request): | |
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") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
25 request.args["before"] = [""] |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
26 request.args["reverse"] = ["1"] |
1058 | 27 yield 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 |
31 @defer.inlineCallbacks | |
32 def on_data_post(self, request): | |
33 profile = self.getProfile(request) | |
34 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
|
35 self.pageError(request, C.HTTP_FORBIDDEN) |
1216 | 36 type_ = self.getPostedData(request, "type") |
37 if type_ == "comment": | |
38 service, node, body = self.getPostedData(request, ("service", "node", "body")) | |
1058 | 39 |
40 if not body: | |
41 self.pageError(request, C.HTTP_BAD_REQUEST) | |
1216 | 42 mb_data = {"content": body} |
1058 | 43 try: |
1216 | 44 yield self.host.bridgeCall("mbSend", service, node, 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_)) |