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 |
|
7 from sat.tools.common import uri as xmpp_uri |
|
8 log = getLogger('pages/forum') |
|
9 import json |
|
10 """forum handling pages""" |
|
11 |
|
12 name = u'forums' |
|
13 access = C.PAGES_ACCESS_PUBLIC |
|
14 template = u"forum/overview.html" |
|
15 |
|
16 def parse_url(self, request): |
|
17 self.getPathArgs(request, ['service', 'node', 'forum_key'], |
|
18 service = u'@jid', |
|
19 node = u'@', |
|
20 forum_key = u'') |
|
21 |
|
22 def getLinks(self, forums): |
|
23 for forum in forums: |
|
24 try: |
|
25 uri = forum['uri'] |
|
26 except KeyError: |
|
27 pass |
|
28 else: |
|
29 uri = xmpp_uri.parseXMPPUri(uri) |
|
30 service = uri[u'path'] |
|
31 node = uri[u'node'] |
|
32 forum['http_url'] = self.getPageByName(u'forum_topics').getURL(service, node) |
|
33 if u'sub-forums' in forum: |
|
34 getLinks(self, forum[u'sub-forums']) |
|
35 |
|
36 @defer.inlineCallbacks |
|
37 def prepare_render(self, request): |
|
38 data = self.getRData(request) |
|
39 template_data = request.template_data |
|
40 service, node, key = data[u'service'], data[u'node'], data[u'forum_key'] |
|
41 profile = self.getProfile(request) or C.SERVICE_PROFILE |
|
42 |
|
43 forums_raw = yield self.host.bridgeCall('forumsGet', service.full() if service else u'', node, key, profile) |
|
44 forums = json.loads(forums_raw) |
|
45 getLinks(self, forums) |
|
46 |
|
47 template_data[u'forums'] = forums |