From 56fbf221082bce439fef6e975058367cf4d2ce79 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 4 Jan 2022 14:57:39 +0100 Subject: [PATCH] [refactor] stop SwitchableSetting from subclassing Setting Previously the default_value was abused for the cookie name. Having SwitchableSetting subclass Setting doesn't even make sense in the first place since none of the Setting methods apply. --- searx/preferences.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index ae158773a..7ea81ce46 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -207,11 +207,12 @@ class Choice: id: str -class SwitchableSetting(Setting): +class SwitchableSetting: """Base class for settings that can be turned on && off""" - def __init__(self, default_value, locked: bool, choices: Iterable[Choice]): - super().__init__(default_value, locked) + def __init__(self, name: str, locked: bool, choices: Iterable[Choice]): + self.name = name + self.locked = locked self.choices = choices self.enabled: Set[str] = set() self.disabled: Set[str] = set() @@ -245,10 +246,10 @@ class SwitchableSetting(Setting): if choice.id not in items: self.enabled.add(choice.id) - def save(self, resp: flask.Response): # pylint: disable=arguments-differ + def save(self, resp: flask.Response): """Save cookie in the HTTP reponse obect""" - resp.set_cookie('disabled_{0}'.format(self.value), ','.join(self.disabled), max_age=COOKIE_MAX_AGE) - resp.set_cookie('enabled_{0}'.format(self.value), ','.join(self.enabled), max_age=COOKIE_MAX_AGE) + resp.set_cookie('disabled_{0}'.format(self.name), ','.join(self.disabled), max_age=COOKIE_MAX_AGE) + resp.set_cookie('enabled_{0}'.format(self.name), ','.join(self.enabled), max_age=COOKIE_MAX_AGE) def get_disabled(self): disabled = self.disabled