From 257e3f33ef9a27cfff249647a7aaf3ccfa1118ab Mon Sep 17 00:00:00 2001 From: DUO Labs Date: Tue, 18 Jan 2022 15:39:56 -0500 Subject: [PATCH] Skip loading autocomplete.js if `WHOOGLE_AUTOCOMPLETE=0` (#611) Bypasses autocomplete.js if `WHOOGLE_AUTOCOMPLETE` is set to 0 --- app/routes.py | 6 +++++- app/templates/display.html | 4 +++- app/templates/index.html | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/routes.py b/app/routes.py index 44206d1..0cd9ecb 100644 --- a/app/routes.py +++ b/app/routes.py @@ -37,6 +37,9 @@ newest_version = int(''.join(filter(str.isdigit, newest_version))) newest_version = '' if current_version >= newest_version \ else newest_version +ac_var = 'WHOOGLE_AUTOCOMPLETE' +autocomplete_enabled = os.getenv(ac_var, '1') + def auth_required(f): @wraps(f) @@ -201,6 +204,7 @@ def index(): languages=app.config['LANGUAGES'], countries=app.config['COUNTRIES'], themes=app.config['THEMES'], + autocomplete_enabled=autocomplete_enabled, translation=app.config['TRANSLATIONS'][ g.user_config.get_localization_lang() ], @@ -246,7 +250,6 @@ def search_html(): @app.route(f'/{Endpoint.autocomplete}', methods=['GET', 'POST']) def autocomplete(): - ac_var = 'WHOOGLE_AUTOCOMPLETE' if os.getenv(ac_var) and not read_config_bool(ac_var): return jsonify({}) @@ -344,6 +347,7 @@ def search(): query=urlparse.unquote(query), search_type=search_util.search_type, config=g.user_config, + autocomplete_enabled=autocomplete_enabled, lingva_url=app.config['TRANSLATE_URL'], translation=translation, translate_to=translate_to, diff --git a/app/templates/display.html b/app/templates/display.html index fe39df7..e4eea3e 100644 --- a/app/templates/display.html +++ b/app/templates/display.html @@ -35,7 +35,9 @@ {{ response|safe }} {% include 'footer.html' %} - +{% if autocomplete_enabled == '1' %} + +{% endif %} diff --git a/app/templates/index.html b/app/templates/index.html index 785b5a5..a05f3b4 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -17,7 +17,9 @@ - + {% if autocomplete_enabled == '1' %} + + {% endif %}