summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-04-13 17:08:19 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2022-05-07 17:58:30 +0200
commited2a4c80879d2d3741514ea1117ab672b8f55d54 (patch)
tree6a1cb65e74ceade9372f65e2cfb7cb9e04322d3e /searx/webapp.py
parent9177172ea21852e16f00896806bf1b573fd9bb8f (diff)
downloadsearxng-ed2a4c80879d2d3741514ea1117ab672b8f55d54.tar.gz
searxng-ed2a4c80879d2d3741514ea1117ab672b8f55d54.zip
[mod] client_settings: pass settings from server to JS client
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 3d3f736a5..b91e96df1 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -10,6 +10,7 @@ import hmac
import json
import os
import sys
+import base64
from datetime import datetime, timedelta
from timeit import default_timer
@@ -444,7 +445,36 @@ def get_pretty_url(parsed_url: urllib.parse.ParseResult):
return [parsed_url.scheme + "://" + parsed_url.netloc, path]
+def get_client_settings():
+ req_pref = request.preferences
+ return {
+ 'autocomplete_provider': req_pref.get_value('autocomplete'),
+ 'http_method': req_pref.get_value('method'),
+ 'infinite_scroll': req_pref.get_value('infinite_scroll'),
+ 'translations': get_translations(),
+ 'search_on_category_select': req_pref.plugins.choices['searx.plugins.search_on_category_select'],
+ 'hotkeys': req_pref.plugins.choices['searx.plugins.vim_hotkeys'],
+ 'theme_static_path': custom_url_for('static', filename='themes/simple'),
+ }
+
+
def render(template_name: str, override_theme: str = None, **kwargs):
+
+ kwargs['client_settings'] = str(
+ base64.b64encode(
+ bytes(
+ json.dumps(get_client_settings()),
+ encoding='utf-8',
+ )
+ ), encoding='utf-8',
+ )
+
+ # obsolete, only needed by oscar
+ kwargs['autocomplete'] = request.preferences.get_value('autocomplete')
+ kwargs['method'] = request.preferences.get_value('method')
+ kwargs['infinite_scroll'] = request.preferences.get_value('infinite_scroll')
+ kwargs['translations'] = json.dumps(get_translations(), separators=(',', ':'))
+
# values from the HTTP requests
kwargs['endpoint'] = 'results' if 'q' in kwargs else request.endpoint
kwargs['cookies'] = request.cookies
@@ -452,9 +482,6 @@ def render(template_name: str, override_theme: str = None, **kwargs):
# values from the preferences
kwargs['preferences'] = request.preferences
- kwargs['method'] = request.preferences.get_value('method')
- kwargs['autocomplete'] = request.preferences.get_value('autocomplete')
- kwargs['infinite_scroll'] = request.preferences.get_value('infinite_scroll')
kwargs['results_on_new_tab'] = request.preferences.get_value('results_on_new_tab')
kwargs['advanced_search'] = request.preferences.get_value('advanced_search')
kwargs['query_in_title'] = request.preferences.get_value('query_in_title')
@@ -466,7 +493,6 @@ def render(template_name: str, override_theme: str = None, **kwargs):
# i18n
kwargs['language_codes'] = [l for l in languages if l[0] in settings['search']['languages']]
- kwargs['translations'] = json.dumps(get_translations(), separators=(',', ':'))
locale = request.preferences.get_value('locale')
kwargs['locale_rfc5646'] = _get_locale_rfc5646(locale)