Mercurial > libervia-web
annotate libervia/pages/forums/view/page_meta.py @ 1145:29eb15062416
pages: set __name__ for imported pages
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Jan 2019 08:41:43 +0100 |
parents | 28e3eb3bb217 |
children | 0f37b65fe7c2 |
rev | line source |
---|---|
1058 | 1 #!/usr/bin/env python2.7 |
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 |
11 name = u"forum_view" | |
12 access = C.PAGES_ACCESS_PUBLIC | |
13 template = u"forum/view.html" | |
14 | |
15 | |
16 def parse_url(self, request): | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
17 self.getPathArgs(request, ["service", "node"], 2, service=u"jid") |
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 |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
24 blog_page = self.getPageByName(u"blog_view") |
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) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
28 request.template_data[u"login_url"] = self.getPageRedirectURL(request) |
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: | |
35 self.pageError(request, C.HTTP_UNAUTHORIZED) | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
36 type_ = self.getPostedData(request, u"type") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
37 if type_ == u"comment": |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
38 service, node, body = self.getPostedData(request, (u"service", u"node", u"body")) |
1058 | 39 |
40 if not body: | |
41 self.pageError(request, C.HTTP_BAD_REQUEST) | |
42 mb_data = {u"content": body} | |
43 try: | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1077
diff
changeset
|
44 yield self.host.bridgeCall(u"mbSend", service, node, mb_data, profile) |
1058 | 45 except Exception as e: |
46 if u"forbidden" in unicode(e): | |
47 self.pageError(request, 401) | |
48 else: | |
49 raise e | |
50 else: | |
51 log.warning(_(u"Unhandled data type: {}").format(type_)) |