From 2c7ac4f8af6d442483b3fd0ebedbf97e9534c2bb Mon Sep 17 00:00:00 2001 From: Israel Yago Pereira Date: Fri, 17 Dec 2021 16:26:54 -0300 Subject: [PATCH 1/3] Fix image_proxy not updating on save --- searx/preferences.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index 9698240f9..ba2c3d33d 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -216,6 +216,25 @@ class MapSetting(Setting): resp.set_cookie(name, self.key, max_age=COOKIE_MAX_AGE) +class BoolSetting(Setting): + def parse(self, data): + if data == '1' or data == 'true': + data = True + if data == '0' or data == '' or data == '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 == 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 +366,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'), -- GitLab From ba22714a7bc995548b8f6dc6a6d1a02c59b724c5 Mon Sep 17 00:00:00 2001 From: Israel Yago Pereira Date: Fri, 17 Dec 2021 16:33:53 -0300 Subject: [PATCH 2/3] Fixes for pylint --- searx/preferences.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index ba2c3d33d..c64fb5b27 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -217,10 +217,11 @@ class MapSetting(Setting): class BoolSetting(Setting): + """Setting of a value that has to be either ON or OFF""" def parse(self, data): - if data == '1' or data == 'true': + if data in ('1', 'true'): data = True - if data == '0' or data == '' or data == 'false': + if data in ('0', '', 'false'): data = False if not isinstance(data, bool): @@ -231,7 +232,7 @@ class BoolSetting(Setting): """Save cookie ``name`` in the HTTP reponse object """ state = 'false' - if self.value == True: + if self.value is True: state = 'true' resp.set_cookie(name, state, max_age=COOKIE_MAX_AGE) -- GitLab From 09e6ecb0b9663598acb6b0a5f39f0e50895a2b92 Mon Sep 17 00:00:00 2001 From: Israel Yago Pereira Date: Sat, 18 Dec 2021 00:25:54 +0000 Subject: [PATCH 3/3] Handling more cases --- searx/preferences.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index c64fb5b27..3452628fd 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -219,9 +219,9 @@ class MapSetting(Setting): class BoolSetting(Setting): """Setting of a value that has to be either ON or OFF""" def parse(self, data): - if data in ('1', 'true'): + if data in ('1', 'true', 'True'): data = True - if data in ('0', '', 'false'): + if data in ('0', '', 'false', 'False'): data = False if not isinstance(data, bool): -- GitLab