view libervia/pages/forums/list/page_meta.py @ 1124:28e3eb3bb217

files reorganisation and installation rework: - files have been reorganised to follow other SàT projects and usual Python organisation (no more "/src" directory) - VERSION file is now used, as for other SàT projects - replace the overcomplicated setup.py be a more sane one. Pyjamas part is not compiled anymore by setup.py, it must be done separatly - removed check for data_dir if it's empty - installation tested working in virtual env - libervia launching script is now in bin/libervia
author Goffi <goffi@goffi.org>
date Sat, 25 Aug 2018 17:59:48 +0200
parents src/pages/forums/list/page_meta.py@cdd389ef97bc
children 29eb15062416
line wrap: on
line source

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

from libervia.server.constants import Const as C
from twisted.internet import defer
from sat.core.log import getLogger
from sat.core.i18n import _
from sat.tools.common import uri as xmpp_uri

log = getLogger("pages/forum")
import json

"""forum handling pages"""

name = u"forums"
access = C.PAGES_ACCESS_PUBLIC
template = u"forum/overview.html"


def parse_url(self, request):
    self.getPathArgs(
        request,
        ["service", "node", "forum_key"],
        service=u"@jid",
        node=u"@",
        forum_key=u"",
    )


def getLinks(self, forums):
    for forum in forums:
        try:
            uri = forum["uri"]
        except KeyError:
            pass
        else:
            uri = xmpp_uri.parseXMPPUri(uri)
            service = uri[u"path"]
            node = uri[u"node"]
            forum["http_url"] = self.getPageByName(u"forum_topics").getURL(service, node)
        if u"sub-forums" in forum:
            getLinks(self, forum[u"sub-forums"])


@defer.inlineCallbacks
def prepare_render(self, request):
    data = self.getRData(request)
    template_data = request.template_data
    service, node, key = data[u"service"], data[u"node"], data[u"forum_key"]
    profile = self.getProfile(request) or C.SERVICE_PROFILE

    try:
        forums_raw = yield self.host.bridgeCall(
            "forumsGet", service.full() if service else u"", node, key, profile
        )
    except Exception as e:
        log.warning(_(u"Can't retrieve forums: {msg}").format(msg=e))
        forums = []
    else:
        forums = json.loads(forums_raw)
    getLinks(self, forums)

    template_data[u"forums"] = forums