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 <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2020-02-23 20:56:05 +01:00
parent 179be12732
commit 1cae4fa88d
2 changed files with 25 additions and 21 deletions

View File

@ -326,43 +326,51 @@ class Preferences(object):
['general'], choices=categories + ['none'] ['general'], choices=categories + ['none']
), ),
'language': SearchLanguageSetting( 'language': SearchLanguageSetting(
settings['search']['default_lang'], settings['search'].get('default_lang', ''),
choices=list(LANGUAGE_CODES) + [''] choices=list(LANGUAGE_CODES) + ['']
), ),
'locale': EnumStringSetting( 'locale': EnumStringSetting(
settings['ui']['default_locale'], settings['ui'].get('default_locale', ''),
choices=list(settings['locales'].keys()) + [''] choices=list(settings['locales'].keys()) + ['']
), ),
'autocomplete': EnumStringSetting( 'autocomplete': EnumStringSetting(
settings['search']['autocomplete'], settings['search'].get('autocomplete', ''),
choices=list(autocomplete.backends.keys()) + [''] choices=list(autocomplete.backends.keys()) + ['']
), ),
'image_proxy': MapSetting( 'image_proxy': MapSetting(
settings['server']['image_proxy'], settings['server'].get('image_proxy', False),
map={ '': settings['server']['image_proxy'], map={
'0': False, '': settings['server'].get('image_proxy', 0),
'1': True, '0': False,
'True': True, '1': True,
'False': False} 'True': True,
'False': False
}
), ),
'method': EnumStringSetting( 'method': EnumStringSetting(
'POST', 'POST',
choices=('GET', 'POST') choices=('GET', 'POST')
), ),
'safesearch': MapSetting( 'safesearch': MapSetting(
settings['search']['safe_search'], settings['search'].get('safe_search', 0),
map={'0': 0, map={
'1': 1, '0': 0,
'2': 2}), '1': 1,
'2': 2
}
),
'theme': EnumStringSetting( 'theme': EnumStringSetting(
settings['ui']['default_theme'], settings['ui'].get('default_theme', 'oscar'),
choices=themes choices=themes
), ),
'results_on_new_tab': MapSetting( 'results_on_new_tab': MapSetting(
False, False,
map ={'0': False, '1': True, map={
'False': False, '0': False,
'True': True} '1': True,
'False': False,
'True': True
}
), ),
'doi_resolver': MultipleChoiceSetting( 'doi_resolver': MultipleChoiceSetting(
['oadoi.org'], choices=DOI_RESOLVERS ['oadoi.org'], choices=DOI_RESOLVERS

View File

@ -3,8 +3,6 @@ general:
instance_name : "searx_test" instance_name : "searx_test"
search: search:
safe_search : 0
autocomplete : ""
language: "all" language: "all"
server: server:
@ -12,14 +10,12 @@ server:
bind_address : 127.0.0.1 bind_address : 127.0.0.1
secret_key : "ultrasecretkey" # change this! secret_key : "ultrasecretkey" # change this!
base_url : False base_url : False
image_proxy : False
http_protocol_version : "1.0" http_protocol_version : "1.0"
ui: ui:
static_path : "" static_path : ""
templates_path : "" templates_path : ""
default_theme : oscar default_theme : oscar
default_locale : ""
outgoing: outgoing:
request_timeout : 1.0 # seconds request_timeout : 1.0 # seconds