view pages/social_contract/page_meta.py @ 33:2f0a33b117d3

presentation: docker image are available again
author Goffi <goffi@goffi.org>
date Mon, 11 Dec 2023 01:12:33 +0100
parents e7c7327f9f25
children
line wrap: on
line source

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

import os.path
from libervia.backend.tools.common.template import safe
from libervia.web.server import session_iface

name = "social_contract"
template = "social_contract/social_contract.html"
social_contracts = {}


def prepare_render(self, request):
    global social_contracts
    session_data = self.host.get_session_data(request, session_iface.IWebSession)
    if session_data.locale is None:
        locale = "en"
    else:
        locale = session_data.locale
        if '_' in locale:
            locale = locale[:locale.find('_')]

    try:
        social_contract = social_contracts[locale]
    except KeyError:
        # we don't have the document in cache
        build_path = self.host.get_build_path(self.vhost_root.site_name)

        if locale == "fr":
            # main social contract is in French, so we don't have suffix in this case
            filename = "CONTRAT_SOCIAL.html"
        else:
            filename = "CONTRAT_SOCIAL_{locale}.html".format(locale=locale)

        filepath = os.path.join(build_path, filename)
        if not os.path.isfile(filepath):
            # there is not translation for this locale, we use English one as default
            filename = "CONTRAT_SOCIAL_en.html"
            filepath = os.path.join(build_path, filename)

        with open(filepath) as f:
            social_contracts[locale] = safe(f.read())

        social_contract = social_contracts[locale]

    request.template_data["social_contract"] = social_contract