comparison pages/social_contract/page_meta.py @ 6:9ce41ef66dfa

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