From 58a059b94afee29767303b399b48629985a48942 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 22 Apr 2021 13:57:43 +0200 Subject: refactor base template, language selector --- talermerchantdemos/survey/survey.py | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'talermerchantdemos/survey/survey.py') diff --git a/talermerchantdemos/survey/survey.py b/talermerchantdemos/survey/survey.py index 1b06218..466c14d 100644 --- a/talermerchantdemos/survey/survey.py +++ b/talermerchantdemos/survey/survey.py @@ -30,7 +30,13 @@ from flask_babel import force_locale from flask_babel import gettext import traceback from taler.util.talerconfig import TalerConfig, ConfigurationError -from ..httpcommon import backend_get, backend_post, self_localized, BackendException +from ..httpcommon import ( + backend_get, + backend_post, + self_localized, + BackendException, + make_utility_processor, +) import sys if not sys.version_info.major == 3 and sys.version_info.minor >= 6: @@ -85,31 +91,9 @@ def get_locale(): return "en" -## -# Make the environment available into templates. -# -# @return the environment-reading function. -@app.context_processor -def utility_processor(): - def env(name, default=None): - return os.environ.get(name, default) - - def prettydate(talerdate): - parsed_time = re.search(r"/Date\(([0-9]+)\)/", talerdate) - if not parsed_time: - return "malformed date given" - parsed_time = int(parsed_time.group(1)) - timestamp = datetime.datetime.fromtimestamp(parsed_time) - # returns the YYYY-MM-DD date format. - return timestamp.strftime("%Y-%b-%d") - - def getactive(): - return "survey" - - def getlang(): - return get_locale() - - return dict(env=env, prettydate=prettydate, getactive=getactive, getlang=getlang) +# Add context processor that will make additional variables +# and functions available in the template. +app.context_processor(make_utility_processor("survey")) ## -- cgit v1.2.3