diff --git a/searx/preferences.py b/searx/preferences.py index 9698240f984d633b6d0f130c7c229973397e53c9..3452628fdefbc6f90dfecd3b83ae0aa565bb1608 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -216,6 +216,26 @@ class MapSetting(Setting): resp.set_cookie(name, self.key, max_age=COOKIE_MAX_AGE) +class BoolSetting(Setting): + """Setting of a value that has to be either ON or OFF""" + def parse(self, data): + if data in ('1', 'true', 'True'): + data = True + if data in ('0', '', 'false', 'False'): + data = False + + if not isinstance(data, bool): + raise ValidationException('Expected a bool value, got "{}" ({})'.format(data, type(data))) + self.value = data + + def save(self, name, resp): + """Save cookie ``name`` in the HTTP reponse object + """ + state = 'false' + if self.value is True: + state = 'true' + resp.set_cookie(name, state, max_age=COOKIE_MAX_AGE) + class SwitchableSetting(Setting): """ Base class for settings that can be turned on && off""" @@ -347,17 +367,22 @@ class Preferences: is_locked('autocomplete'), choices=list(autocomplete.backends.keys()) + [''] ), - 'image_proxy': MapSetting( + 'image_proxy': BoolSetting( settings['server'].get('image_proxy', False), is_locked('image_proxy'), - map={ - '': settings['server'].get('image_proxy', 0), - '0': False, - '1': True, - 'True': True, - 'False': False - } + bool=settings['search'].get('image_proxy', False) ), + # 'image_proxy': MapSetting( + # settings['server'].get('image_proxy', False), + # is_locked('image_proxy'), + # map={ + # '': settings['search'].get('image_proxy', False), + # '0': False, + # '1': True, + # 'True': True, + # 'False': False + # } + # ), 'method': EnumStringSetting( settings['server'].get('method', 'POST'), is_locked('method'),