annotate libervia/pages/forums/topics/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/forums/topics/page_meta.py@cdd389ef97bc
children 29eb15062416
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.internet import defer
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.i18n import _
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.core.log import getLogger
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.tools.common import uri as xmpp_uri
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
9
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
10 log = getLogger("pages/forums/topics")
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 name = u"forum_topics"
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PUBLIC
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = u"forum/view_topics.html"
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):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
18 self.getPathArgs(request, ["service", "node"], 2, service=u"jid")
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 @defer.inlineCallbacks
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 def prepare_render(self, request):
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 profile = self.getProfile(request) or C.SERVICE_PROFILE
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 data = self.getRData(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
25 service, node = data[u"service"], data[u"node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
26 request.template_data.update({u"service": service, u"node": node})
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
28 topics, metadata = yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
29 u"forumTopicsGet", service.full(), node, {}, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
30 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
31 template_data[u"identities"] = identities = {}
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 for topic in topics:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
33 parsed_uri = xmpp_uri.parseXMPPUri(topic[u"uri"])
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
34 author = topic[u"author"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
35 topic[u"http_uri"] = self.getPageByName(u"forum_view").getURL(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
36 parsed_uri[u"path"], parsed_uri[u"node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
37 )
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 if author not in identities:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
39 identities[topic[u"author"]] = yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
40 u"identityGet", author, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
41 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
42 template_data[u"topics"] = topics
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
43
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 @defer.inlineCallbacks
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def on_data_post(self, request):
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 profile = self.getProfile(request)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 if profile is None:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.pageError(request, C.HTTP_UNAUTHORIZED)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
50 type_ = self.getPostedData(request, u"type")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
51 if type_ == u"new_topic":
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
52 service, node, title, body = self.getPostedData(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
53 request, (u"service", u"node", u"title", u"body")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
54 )
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 if not title or not body:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.pageError(request, C.HTTP_BAD_REQUEST)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 topic_data = {u"title": title, u"content": body}
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
60 yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
61 u"forumTopicCreate", service, node, topic_data, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
62 )
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 except Exception as e:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 if u"forbidden" in unicode(e):
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.pageError(request, 401)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 else:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 raise e
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 else:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 log.warning(_(u"Unhandled data type: {}").format(type_))