diff options
Diffstat (limited to 'talermerchantdemos/landing/landing.py')
-rw-r--r-- | talermerchantdemos/landing/landing.py | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/talermerchantdemos/landing/landing.py b/talermerchantdemos/landing/landing.py index b628deb..13c8dc4 100644 --- a/talermerchantdemos/landing/landing.py +++ b/talermerchantdemos/landing/landing.py @@ -22,14 +22,16 @@ import datetime import base64 import logging import flask -from flask import request +import uwsgi +import werkzeug +from flask import request, url_for from flask_babel import Babel from flask_babel import refresh from flask_babel import force_locale from flask_babel import gettext from werkzeug.middleware.proxy_fix import ProxyFix import traceback -from taler.util.talerconfig import TalerConfig, ConfigurationError +from ..util.talerconfig import TalerConfig, ConfigurationError from ..httpcommon import ( backend_get, backend_post, @@ -53,12 +55,10 @@ app.wsgi_app = ProxyFix(app.wsgi_app, x_host=1, x_prefix=1) app.debug = True app.secret_key = base64.b64encode(os.urandom(64)).decode("utf-8") +logging.basicConfig() LOGGER = logging.getLogger(__name__) -TC = TalerConfig.from_env() try: - BACKEND_URL = TC["frontends"]["backend"].value_string(required=True) - CURRENCY = TC["taler"]["currency"].value_string(required=True) - APIKEY = TC["frontends"]["backend_apikey"].value_string(required=True) + CURRENCY = uwsgi.opt["currency"].decode("utf-8") except ConfigurationError as ce: print(ce) exit(1) @@ -80,7 +80,7 @@ LOGGER.info( # Add context processor that will make additional variables # and functions available in the template. -app.context_processor(make_utility_processor("landing")) +app.context_processor(make_utility_processor("landing", os.environ.get ("TALER_ENV_URL_INTRO"))) ## # Exception handler to capture all the unmanaged errors. @@ -92,6 +92,7 @@ app.context_processor(make_utility_processor("landing")) def internal_error(e): return flask.render_template( "landing-error.html.j2", + page_title=gettext("GNU Taler Demo: Error"), message=gettext("Internal error"), stack=traceback.format_exc(), ) @@ -119,8 +120,7 @@ def favicon(): def index(): default = "en" target = flask.request.accept_languages.best_match(translations, default) - return flask.redirect(target + "/", code=302) - + return flask.redirect(url_for ('index') + target + "/", code=302) ## # Serve the internationalized main index page. @@ -129,11 +129,19 @@ def index(): @app.route("/<lang>/", methods=["GET"]) def start(lang): + # get_locale defaults to english, hence the + # condition below happens only when lang is + # wrong or unsupported, respond 404. + if lang != get_locale(): + raise werkzeug.exceptions.NotFound() + if x := os.environ.get("TALER_ENV_URL_BANK"): - bank_register_url = "/".join([x.strip("/"), f"{lang}/register"]) - bank_public_accounts_url = "/".join([x.strip("/"), f"{lang}/public-accounts"]) + bank_url = x + bank_register_url = bank_url + bank_public_accounts_url = bank_url + "#public-accounts" else: bank_register_url = "#" + bank_url = "#" bank_public_accounts_url = "#" if x := os.environ.get("TALER_ENV_URL_MERCHANT_BLOG"): @@ -146,26 +154,25 @@ def start(lang): else: merchant_donations_url = "#" - if x := os.environ.get("TALER_ENV_URL_MERCHANT_SURVEY"): - merchant_survey_url = "/".join([x.strip("/"), lang]) - else: - merchant_survey_url = "#" - return flask.render_template( "landing-index.html.j2", merchant_currency=CURRENCY, + page_title=gettext("GNU Taler Demo"), bank_register_url=bank_register_url, + bank_url=bank_url, bank_public_accounts_url=bank_public_accounts_url, merchant_blog_url=merchant_blog_url, merchant_donations_url=merchant_donations_url, - merchant_survey_url=merchant_survey_url, ) -@app.errorhandler(404) +@app.errorhandler(404) # How to trigger this? +@app.errorhandler(werkzeug.exceptions.NotFound) def handler_404(e): return flask.render_template( - "landing-error.html.j2", message=gettext("Page not found") + "landing-error.html.j2", + page_title=gettext("GNU Taler Demo: Error"), + message=gettext("Page not found") ) @@ -173,5 +180,6 @@ def handler_404(e): def handler_405(e): return flask.render_template( "landing-error.html.j2", + page_title=gettext("GNU Taler Demo: Error"), message=gettext("HTTP method not allowed for this page"), ) |