From d54a95e0f9c689f2bbaaea90a3a16a855a408823 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 17 Aug 2022 13:50:34 +0200 Subject: allow loading packages from zip files through web UI and listing installed mappings --- src/hydrilla/proxy/web_ui/root.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/hydrilla/proxy/web_ui/root.py') diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index 194251e..64d6be1 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -37,33 +37,36 @@ from threading import Lock import jinja2 import flask -from ...translations import smart_gettext as _ +from ...translations import translation as make_translation +from ... import versions from .. import state as st from .. import http_messages - from . import repos from . import packages +from . import _app -class WebUIApp(flask.Flask): +class WebUIAppImpl(_app.WebUIApp): def __init__(self): super().__init__(__name__) self.jinja_options = { **self.jinja_options, 'loader': jinja2.PackageLoader(__package__), - 'autoescape': jinja2.select_autoescape() + 'autoescape': jinja2.select_autoescape(['html.jinja']), + 'extensions': [ + *self.jinja_options.get('extensions', []), + 'jinja2.ext.i18n' + ] } for blueprint in [repos.bp, packages.bp]: self.register_blueprint(blueprint) - _haketilo_state: st.HaketiloState - # Flask app is not thread-safe and has to be accompanied by an ugly lock. This # can cause slow requests to block other requests, so we might need a better # workaround at some later point. -app = WebUIApp() +app = WebUIAppImpl() app_lock = Lock() @@ -83,6 +86,8 @@ def process_request( with app_lock: app._haketilo_state = state + app.jinja_env.install_gettext_translations(make_translation()) + flask_response = app.test_client().open( path = path, base_url = 'https://hkt.mitm.it', -- cgit v1.2.3