0
|
1 #!/usr/bin/env python2.7 |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 from libervia.server.constants import Const as C |
|
5 from twisted.words.protocols.jabber import jid |
|
6 from twisted.internet import defer |
|
7 from sat.core.i18n import _ |
|
8 from sat.core.log import getLogger |
|
9 |
|
10 log = getLogger(__name__) |
|
11 |
6
|
12 name = "news" |
|
13 template = "news/news.html" |
0
|
14 service = None |
|
15 node = None |
|
16 |
|
17 |
|
18 @defer.inlineCallbacks |
|
19 def prepare_render(self, request): |
|
20 global service, node |
|
21 if service is None: |
6
|
22 blog_dict = self.getConfig('news_blog_dict', {}) |
0
|
23 try: |
|
24 service = jid.JID(blog_dict['service']) |
|
25 except RuntimeError as e: |
6
|
26 log.warning(_("Can't parse service in news_blog_dict: {e}").format(e=e)) |
0
|
27 service = None |
|
28 except KeyError: |
6
|
29 log.warnning(_("Missing service in news_blog_dict")) |
0
|
30 service = None |
6
|
31 node = blog_dict.get('node', '') |
0
|
32 if not blog_dict or service is None: |
6
|
33 log.warning(_('No value set for news_blog_dict, "news" page can\'t be used')) |
0
|
34 self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE) |
|
35 |
|
36 data = self.getRData(request) |
6
|
37 data['service'] = service |
|
38 data['node'] = node |
0
|
39 |
|
40 # self.checkCache( |
|
41 # request, C.CACHE_PUBSUB, service=service, node=node, short="microblog") |
|
42 |
|
43 # we now need blog items, using blog common page |
|
44 # this will fill the "items" template data |
6
|
45 blog_page = self.getPageByName("blog_view") |
0
|
46 yield blog_page.prepare_render(self, request) |