From 1cae4fa88da1cfad6f953b0ebc170946f3af6c89 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 23 Feb 2020 20:56:05 +0100 Subject: [PATCH] preferences.py: implement defaults if unset Implemnts defaults for: - search.default_lang, search.autocomplete, search.safe_search, - ui.default_theme, ui.default_locale - server.image_proxy This fixes also: https://github.com/asciimoo/searx/pull/1860#issuecomment-590082955 Signed-off-by: Markus Heiser --- searx/preferences.py | 42 ++++++++++++++++++++++++---------------- searx/settings_robot.yml | 4 ---- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index b0f8887c3..f70aee37a 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -326,43 +326,51 @@ class Preferences(object): ['general'], choices=categories + ['none'] ), 'language': SearchLanguageSetting( - settings['search']['default_lang'], + settings['search'].get('default_lang', ''), choices=list(LANGUAGE_CODES) + [''] ), 'locale': EnumStringSetting( - settings['ui']['default_locale'], + settings['ui'].get('default_locale', ''), choices=list(settings['locales'].keys()) + [''] ), 'autocomplete': EnumStringSetting( - settings['search']['autocomplete'], + settings['search'].get('autocomplete', ''), choices=list(autocomplete.backends.keys()) + [''] ), 'image_proxy': MapSetting( - settings['server']['image_proxy'], - map={ '': settings['server']['image_proxy'], - '0': False, - '1': True, - 'True': True, - 'False': False} + settings['server'].get('image_proxy', False), + map={ + '': settings['server'].get('image_proxy', 0), + '0': False, + '1': True, + 'True': True, + 'False': False + } ), 'method': EnumStringSetting( 'POST', choices=('GET', 'POST') ), 'safesearch': MapSetting( - settings['search']['safe_search'], - map={'0': 0, - '1': 1, - '2': 2}), + settings['search'].get('safe_search', 0), + map={ + '0': 0, + '1': 1, + '2': 2 + } + ), 'theme': EnumStringSetting( - settings['ui']['default_theme'], + settings['ui'].get('default_theme', 'oscar'), choices=themes ), 'results_on_new_tab': MapSetting( False, - map ={'0': False, '1': True, - 'False': False, - 'True': True} + map={ + '0': False, + '1': True, + 'False': False, + 'True': True + } ), 'doi_resolver': MultipleChoiceSetting( ['oadoi.org'], choices=DOI_RESOLVERS diff --git a/searx/settings_robot.yml b/searx/settings_robot.yml index 25f229e56..33e762689 100644 --- a/searx/settings_robot.yml +++ b/searx/settings_robot.yml @@ -3,8 +3,6 @@ general: instance_name : "searx_test" search: - safe_search : 0 - autocomplete : "" language: "all" server: @@ -12,14 +10,12 @@ server: bind_address : 127.0.0.1 secret_key : "ultrasecretkey" # change this! base_url : False - image_proxy : False http_protocol_version : "1.0" ui: static_path : "" templates_path : "" default_theme : oscar - default_locale : "" outgoing: request_timeout : 1.0 # seconds