comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:09d66acc7c73
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3
4 import os.path
5 from sat.tools.common.template import safe
6 from libervia.server import session_iface
7
8 name = u"social_contract"
9 template = u"social_contract/social_contract.html"
10 social_contracts = {}
11
12
13 def prepare_render(self, request):
14 global social_contracts
15 session_data = self.host.getSessionData(request, session_iface.ISATSession)
16 if session_data.locale is None:
17 locale = u"en"
18 else:
19 locale = session_data.locale
20 if u'_' in locale:
21 locale = locale[:locale.find('_')]
22
23 try:
24 social_contract = social_contracts[locale]
25 except KeyError:
26 # we don't have the document in cache
27 build_path = self.host.getBuildPath(self.vhost_root.site_name)
28
29 if locale == u"fr":
30 # main social contract is in French, so we don't have suffix in this case
31 filename = u"CONTRAT_SOCIAL.html"
32 else:
33 filename = u"CONTRAT_SOCIAL_{locale}.html".format(locale=locale)
34
35 filepath = os.path.join(build_path, filename)
36 if not os.path.isfile(filepath):
37 # there is not translation for this locale, we use English one as default
38 filename = u"CONTRAT_SOCIAL_en.html"
39 filepath = os.path.join(build_path, filename)
40
41 with open(filepath) as f:
42 social_contracts[locale] = safe(f.read().decode('utf-8'))
43
44 social_contract = social_contracts[locale]
45
46 request.template_data[u"social_contract"] = social_contract