diff pages/social_contract/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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pages/social_contract/page_meta.py	Sun May 26 22:26:30 2019 +0200
@@ -0,0 +1,46 @@
+#!/usr/bin/env python2.7
+# -*- coding: utf-8 -*-
+
+import os.path
+from sat.tools.common.template import safe
+from libervia.server import session_iface
+
+name = u"social_contract"
+template = u"social_contract/social_contract.html"
+social_contracts = {}
+
+
+def prepare_render(self, request):
+    global social_contracts
+    session_data = self.host.getSessionData(request, session_iface.ISATSession)
+    if session_data.locale is None:
+        locale = u"en"
+    else:
+        locale = session_data.locale
+        if u'_' 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.getBuildPath(self.vhost_root.site_name)
+
+        if locale == u"fr":
+            # main social contract is in French, so we don't have suffix in this case
+            filename = u"CONTRAT_SOCIAL.html"
+        else:
+            filename = u"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 = u"CONTRAT_SOCIAL_en.html"
+            filepath = os.path.join(build_path, filename)
+
+        with open(filepath) as f:
+            social_contracts[locale] = safe(f.read().decode('utf-8'))
+
+        social_contract = social_contracts[locale]
+
+    request.template_data[u"social_contract"] = social_contract