summaryrefslogtreecommitdiff
path: root/searx/settings_defaults.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-10-21 10:41:57 +0200
committerAlexandre Flament <alex@al-f.net>2021-10-26 10:27:05 +0200
commit60db344cc0715eab4d03dad5629f4c47954c466c (patch)
treeed933547df3bc250d1cac558cb37be0f6b9ba93a /searx/settings_defaults.py
parentdfdf71bf08d48332a30ff982dcc8b4ac499d9c8d (diff)
downloadsearxng-60db344cc0715eab4d03dad5629f4c47954c466c.tar.gz
searxng-60db344cc0715eab4d03dad5629f4c47954c466c.zip
[enh] reduce the available language list
close #406 settings['search']['languages'] contains the languages codes and 'all'
Diffstat (limited to 'searx/settings_defaults.py')
-rw-r--r--searx/settings_defaults.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py
index 49462ccb4..331cd643d 100644
--- a/searx/settings_defaults.py
+++ b/searx/settings_defaults.py
@@ -17,7 +17,7 @@ searx_dir = abspath(dirname(__file__))
logger = logging.getLogger('searx')
OUTPUT_FORMATS = ['html', 'csv', 'json', 'rss']
-LANGUAGE_CODES = ('', 'all') + tuple(l[0] for l in languages)
+LANGUAGE_CODES = ['all'] + list(l[0] for l in languages)
OSCAR_STYLE = ('logicodev', 'logicodev-dark', 'pointhi')
CATEGORY_ORDER = [
'general',
@@ -98,6 +98,18 @@ class SettingsValue:
self.check_type_definition(value)
return value
+
+class SettingSublistValue(SettingsValue):
+ """Check the value is a sublist of type definition.
+ """
+
+ def check_type_definition(self, value: typing.Any) -> typing.Any:
+ if not isinstance(value, list):
+ raise ValueError('The value has to a list')
+ for item in value:
+ if not item in self.type_definition[0]:
+ raise ValueError('{} not in {}'.format(item, self.type_definition))
+
class SettingsDirectoryValue(SettingsValue):
"""Check and update a setting value that is a directory path
"""
@@ -148,7 +160,8 @@ SCHEMA = {
'search': {
'safe_search': SettingsValue((0,1,2), 0),
'autocomplete': SettingsValue(str, ''),
- 'default_lang': SettingsValue(LANGUAGE_CODES, ''),
+ 'default_lang': SettingsValue(tuple(LANGUAGE_CODES + ['']), ''),
+ 'languages': SettingSublistValue(LANGUAGE_CODES, LANGUAGE_CODES),
'ban_time_on_fail': SettingsValue(numbers.Real, 5),
'max_ban_time_on_fail': SettingsValue(numbers.Real, 120),
'formats': SettingsValue(list, OUTPUT_FORMATS),