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']
),
'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'],
settings['server'].get('image_proxy', False),
map={
'': settings['server'].get('image_proxy', 0),
'0': False,
'1': True,
'True': True,
'False': False}
'False': False
}
),
'method': EnumStringSetting(
'POST',
choices=('GET', 'POST')
),
'safesearch': MapSetting(
settings['search']['safe_search'],
map={'0': 0,
settings['search'].get('safe_search', 0),
map={
'0': 0,
'1': 1,
'2': 2}),
'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,
map={
'0': False,
'1': True,
'False': False,
'True': True}
'True': True
}
),
'doi_resolver': MultipleChoiceSetting(
['oadoi.org'], choices=DOI_RESOLVERS

View file

@ -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