comparison libervia/pages/forums/topics/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 f511f8fbbf8a
comparison
equal deleted inserted replaced
1215:f14ab8a25e8b 1216:b2d067339de3
1 #!/usr/bin/env python2.7 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 from libervia.server.constants import Const as C 4 from libervia.server.constants import Const as C
5 from twisted.internet import defer 5 from twisted.internet import defer
6 from sat.core.i18n import _ 6 from sat.core.i18n import _
7 from sat.core.log import getLogger 7 from sat.core.log import getLogger
8 from sat.tools.common import uri as xmpp_uri 8 from sat.tools.common import uri as xmpp_uri
9 9
10 log = getLogger(__name__) 10 log = getLogger(__name__)
11 11
12 name = u"forum_topics" 12 name = "forum_topics"
13 access = C.PAGES_ACCESS_PUBLIC 13 access = C.PAGES_ACCESS_PUBLIC
14 template = u"forum/view_topics.html" 14 template = "forum/view_topics.html"
15 15
16 16
17 def parse_url(self, request): 17 def parse_url(self, request):
18 self.getPathArgs(request, ["service", "node"], 2, service=u"jid") 18 self.getPathArgs(request, ["service", "node"], 2, service="jid")
19 19
20 20
21 @defer.inlineCallbacks 21 @defer.inlineCallbacks
22 def prepare_render(self, request): 22 def prepare_render(self, request):
23 profile = self.getProfile(request) or C.SERVICE_PROFILE 23 profile = self.getProfile(request) or C.SERVICE_PROFILE
24 data = self.getRData(request) 24 data = self.getRData(request)
25 service, node = data[u"service"], data[u"node"] 25 service, node = data["service"], data["node"]
26 request.template_data.update({u"service": service, u"node": node}) 26 request.template_data.update({"service": service, "node": node})
27 template_data = request.template_data 27 template_data = request.template_data
28 topics, metadata = yield self.host.bridgeCall( 28 topics, metadata = yield self.host.bridgeCall(
29 u"forumTopicsGet", service.full(), node, {}, profile 29 "forumTopicsGet", service.full(), node, {}, profile
30 ) 30 )
31 template_data[u"identities"] = identities = {} 31 template_data["identities"] = identities = {}
32 for topic in topics: 32 for topic in topics:
33 parsed_uri = xmpp_uri.parseXMPPUri(topic[u"uri"]) 33 parsed_uri = xmpp_uri.parseXMPPUri(topic["uri"])
34 author = topic[u"author"] 34 author = topic["author"]
35 topic[u"http_uri"] = self.getPageByName(u"forum_view").getURL( 35 topic["http_uri"] = self.getPageByName("forum_view").getURL(
36 parsed_uri[u"path"], parsed_uri[u"node"] 36 parsed_uri["path"], parsed_uri["node"]
37 ) 37 )
38 if author not in identities: 38 if author not in identities:
39 identities[topic[u"author"]] = yield self.host.bridgeCall( 39 identities[topic["author"]] = yield self.host.bridgeCall(
40 u"identityGet", author, profile 40 "identityGet", author, profile
41 ) 41 )
42 template_data[u"topics"] = topics 42 template_data["topics"] = topics
43 43
44 44
45 @defer.inlineCallbacks 45 @defer.inlineCallbacks
46 def on_data_post(self, request): 46 def on_data_post(self, request):
47 profile = self.getProfile(request) 47 profile = self.getProfile(request)
48 if profile is None: 48 if profile is None:
49 self.pageError(request, C.HTTP_FORBIDDEN) 49 self.pageError(request, C.HTTP_FORBIDDEN)
50 type_ = self.getPostedData(request, u"type") 50 type_ = self.getPostedData(request, "type")
51 if type_ == u"new_topic": 51 if type_ == "new_topic":
52 service, node, title, body = self.getPostedData( 52 service, node, title, body = self.getPostedData(
53 request, (u"service", u"node", u"title", u"body") 53 request, ("service", "node", "title", "body")
54 ) 54 )
55 55
56 if not title or not body: 56 if not title or not body:
57 self.pageError(request, C.HTTP_BAD_REQUEST) 57 self.pageError(request, C.HTTP_BAD_REQUEST)
58 topic_data = {u"title": title, u"content": body} 58 topic_data = {"title": title, "content": body}
59 try: 59 try:
60 yield self.host.bridgeCall( 60 yield self.host.bridgeCall(
61 u"forumTopicCreate", service, node, topic_data, profile 61 "forumTopicCreate", service, node, topic_data, profile
62 ) 62 )
63 except Exception as e: 63 except Exception as e:
64 if u"forbidden" in unicode(e): 64 if "forbidden" in str(e):
65 self.pageError(request, 401) 65 self.pageError(request, 401)
66 else: 66 else:
67 raise e 67 raise e
68 else: 68 else:
69 log.warning(_(u"Unhandled data type: {}").format(type_)) 69 log.warning(_("Unhandled data type: {}").format(type_))