summaryrefslogtreecommitdiff
path: root/searx/preferences.py
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-01-04 14:57:39 +0100
committerMartin Fischer <martin@push-f.com>2022-01-06 18:13:13 +0100
commit56fbf221082bce439fef6e975058367cf4d2ce79 (patch)
treea1ab02181c71cda163f47ca8d87612ba79e07471 /searx/preferences.py
parent83f8a8fc6dc7658e062ddcbe779cba57dfaa1cb3 (diff)
downloadsearxng-56fbf221082bce439fef6e975058367cf4d2ce79.tar.gz
searxng-56fbf221082bce439fef6e975058367cf4d2ce79.zip
[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.
Diffstat (limited to 'searx/preferences.py')
-rw-r--r--searx/preferences.py13
1 files 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