Mercurial > libervia-web
annotate src/pages/forums/list/page_meta.py @ 1080:2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 27 Mar 2018 08:36:37 +0200 |
parents | 2290b6ec3991 |
children | cdd389ef97bc |
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.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 | 8 from sat.tools.common import uri as xmpp_uri |
9 log = getLogger('pages/forum') | |
10 import json | |
11 """forum handling pages""" | |
12 | |
13 name = u'forums' | |
14 access = C.PAGES_ACCESS_PUBLIC | |
15 template = u"forum/overview.html" | |
16 | |
17 def parse_url(self, request): | |
18 self.getPathArgs(request, ['service', 'node', 'forum_key'], | |
19 service = u'@jid', | |
20 node = u'@', | |
21 forum_key = u'') | |
22 | |
23 def getLinks(self, forums): | |
24 for forum in forums: | |
25 try: | |
26 uri = forum['uri'] | |
27 except KeyError: | |
28 pass | |
29 else: | |
30 uri = xmpp_uri.parseXMPPUri(uri) | |
31 service = uri[u'path'] | |
32 node = uri[u'node'] | |
33 forum['http_url'] = self.getPageByName(u'forum_topics').getURL(service, node) | |
34 if u'sub-forums' in forum: | |
35 getLinks(self, forum[u'sub-forums']) | |
36 | |
37 @defer.inlineCallbacks | |
38 def prepare_render(self, request): | |
39 data = self.getRData(request) | |
40 template_data = request.template_data | |
41 service, node, key = data[u'service'], data[u'node'], data[u'forum_key'] | |
42 profile = self.getProfile(request) or C.SERVICE_PROFILE | |
43 | |
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
|
44 try: |
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
45 forums_raw = yield self.host.bridgeCall('forumsGet', service.full() if service else u'', node, key, profile) |
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 forums = json.loads(forums_raw) |
1058 | 51 getLinks(self, forums) |
52 | |
53 template_data[u'forums'] = forums |