view pages/news/page_meta.py @ 28:e7c7327f9f25

refactoring: fix imports and names in doc following modules hierarchy refactoring
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 17:48:38 +0200
parents 5fd933e238bb
children
line wrap: on
line source

from libervia.web.server.constants import Const as C
from twisted.words.protocols.jabber import jid
from libervia.backend.core.i18n import _
from libervia.backend.core.log import getLogger

log = getLogger(__name__)

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


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

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

    # self.check_cache(
    #     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.get_page_by_name("blog_view")
    await blog_page.prepare_render(self, request)