view pages/news/page_meta.py @ 0:09d66acc7c73

initial commit, website first draft: - presentation page - documentation (generated from backend and Libervia) - social contract (HTML generated from sat repository) - press/conferences (adapted from former website) - association page (adpated from former website) - news (a selected blog is displayed) - fr i18n
author Goffi <goffi@goffi.org>
date Sun, 26 May 2019 22:26:30 +0200
parents
children 9ce41ef66dfa
line wrap: on
line source

#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from libervia.server.constants import Const as C
from twisted.words.protocols.jabber import jid
from twisted.internet import defer
from sat.core.i18n import _
from sat.core.log import getLogger

log = getLogger(__name__)

name = u"news"
template = u"news/news.html"
service = None
node = None


@defer.inlineCallbacks
def prepare_render(self, request):
    global service, node
    if service is None:
        blog_dict = self.getConfig(u'news_blog_dict', {})
        try:
            service = jid.JID(blog_dict['service'])
        except RuntimeError as e:
            log.warning(_(u"Can't parse service in news_blog_dict: {e}").format(e=e))
            service = None
        except KeyError:
            log.warnning(_(u"Missing service in news_blog_dict"))
            service = None
        node = blog_dict.get('node', u'')
        if not blog_dict or service is None:
            log.warning(_(u'No value set for news_blog_dict, "news" page can\'t be used'))
            self.pageError(request, C.HTTP_SERVICE_UNAVAILABLE)

    data = self.getRData(request)
    data[u'service'] = service
    data[u'node'] = node

    # self.checkCache(
    #     request, C.CACHE_PUBSUB, service=service, node=node, short="microblog")

    # we now need blog items, using blog common page
    # this will fill the "items" template data
    blog_page = self.getPageByName(u"blog_view")
    yield blog_page.prepare_render(self, request)