Mercurial > libervia-website
annotate 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 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python2.7 |
2 # -*- coding: utf-8 -*- | |
3 | |
4 import os.path | |
28
e7c7327f9f25
refactoring: fix imports and names in doc following modules hierarchy refactoring
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
5 from libervia.backend.tools.common.template import safe |
e7c7327f9f25
refactoring: fix imports and names in doc following modules hierarchy refactoring
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
6 from libervia.web.server import session_iface |
0 | 7 |
6 | 8 name = "social_contract" |
9 template = "social_contract/social_contract.html" | |
0 | 10 social_contracts = {} |
11 | |
12 | |
13 def prepare_render(self, request): | |
14 global social_contracts | |
28
e7c7327f9f25
refactoring: fix imports and names in doc following modules hierarchy refactoring
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
15 session_data = self.host.get_session_data(request, session_iface.IWebSession) |
0 | 16 if session_data.locale is None: |
6 | 17 locale = "en" |
0 | 18 else: |
19 locale = session_data.locale | |
6 | 20 if '_' in locale: |
0 | 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 | |
22
5fd933e238bb
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
6
diff
changeset
|
27 build_path = self.host.get_build_path(self.vhost_root.site_name) |
0 | 28 |
6 | 29 if locale == "fr": |
0 | 30 # main social contract is in French, so we don't have suffix in this case |
6 | 31 filename = "CONTRAT_SOCIAL.html" |
0 | 32 else: |
6 | 33 filename = "CONTRAT_SOCIAL_{locale}.html".format(locale=locale) |
0 | 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 | |
6 | 38 filename = "CONTRAT_SOCIAL_en.html" |
0 | 39 filepath = os.path.join(build_path, filename) |
40 | |
41 with open(filepath) as f: | |
6 | 42 social_contracts[locale] = safe(f.read()) |
0 | 43 |
44 social_contract = social_contracts[locale] | |
45 | |
6 | 46 request.template_data["social_contract"] = social_contract |