annotate libervia/pages/forums/list/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 b2d067339de3
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.log import getLogger
1080
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
7 from sat.core.i18n import _
1058
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: 1080
diff changeset
9
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
10 log = getLogger(__name__)
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 import json
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
12
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 """forum handling pages"""
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
15 name = u"forums"
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 access = C.PAGES_ACCESS_PUBLIC
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 template = u"forum/overview.html"
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
19
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 def parse_url(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
21 self.getPathArgs(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
22 request,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
23 ["service", "node", "forum_key"],
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
24 service=u"@jid",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
25 node=u"@",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
26 forum_key=u"",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
27 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
28
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 def getLinks(self, forums):
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 for forum in forums:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
33 uri = forum["uri"]
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 except KeyError:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 pass
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 else:
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 uri = xmpp_uri.parseXMPPUri(uri)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
38 service = uri[u"path"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
39 node = uri[u"node"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
40 forum["http_url"] = self.getPageByName(u"forum_topics").getURL(service, node)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
41 if u"sub-forums" in forum:
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
42 getLinks(self, forum[u"sub-forums"])
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
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 prepare_render(self, request):
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 data = self.getRData(request)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
49 service, node, key = data[u"service"], data[u"node"], data[u"forum_key"]
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 profile = self.getProfile(request) or C.SERVICE_PROFILE
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
1080
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
52 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
53 forums_raw = yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
54 "forumsGet", service.full() if service else u"", node, key, profile
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
55 )
1080
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
56 except Exception as e:
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
57 log.warning(_(u"Can't retrieve forums: {msg}").format(msg=e))
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
58 forums = []
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
59 else:
2c2b8c08e6c9 pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents: 1058
diff changeset
60 forums = json.loads(forums_raw)
1058
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 getLinks(self, forums)
2290b6ec3991 pages (forums): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1080
diff changeset
63 template_data[u"forums"] = forums