diff options
author | Adam Tauber <asciimoo@gmail.com> | 2017-07-10 12:47:25 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-07-10 12:50:13 +0200 |
commit | 38d6ba4066a474c1b13e7ccb6f9ea92b43702a4a (patch) | |
tree | 8ebde856ad55df96385eacd5ab3d276117d5fa99 /searx/preferences.py | |
parent | 36af8f9d676ed28a619c18746e638dc5e2159585 (diff) | |
download | searxng-38d6ba4066a474c1b13e7ccb6f9ea92b43702a4a.tar.gz searxng-38d6ba4066a474c1b13e7ccb6f9ea92b43702a4a.zip |
[enh] generate search url of saved preferences
Diffstat (limited to 'searx/preferences.py')
-rw-r--r-- | searx/preferences.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/searx/preferences.py b/searx/preferences.py index b6a2ec4cc..92fe3853c 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -1,5 +1,6 @@ from searx import settings, autocomplete from searx.languages import language_codes as languages +from searx.url_utils import urlencode COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years @@ -232,7 +233,7 @@ class PluginsSetting(SwitchableSetting): class Preferences(object): - """Stores, validates and saves preferences to cookies""" + """Validates and saves preferences to cookies""" def __init__(self, themes, categories, engines, plugins): super(Preferences, self).__init__() @@ -247,19 +248,40 @@ class Preferences(object): 'image_proxy': MapSetting(settings['server']['image_proxy'], map={'': settings['server']['image_proxy'], '0': False, - '1': True}), + '1': True, + 'True': True, + 'False': False}), 'method': EnumStringSetting('POST', choices=('GET', 'POST')), 'safesearch': MapSetting(settings['search']['safe_search'], map={'0': 0, '1': 1, '2': 2}), 'theme': EnumStringSetting(settings['ui']['default_theme'], choices=themes), - 'results_on_new_tab': MapSetting(False, map={'0': False, '1': True})} + 'results_on_new_tab': MapSetting(False, map={'0': False, + '1': True, + 'False': False, + 'True': True})} self.engines = EnginesSetting('engines', choices=engines) self.plugins = PluginsSetting('plugins', choices=plugins) self.unknown_params = {} - def parse_cookies(self, input_data): + def get_as_url_params(self): + settings_kv = {} + for k, v in self.key_value_settings.items(): + if isinstance(v, MultipleChoiceSetting): + settings_kv[k] = ','.join(v.get_value()) + else: + settings_kv[k] = v.get_value() + + settings_kv['disabled_engines'] = ','.join(self.engines.disabled) + settings_kv['enabled_engines'] = ','.join(self.engines.enabled) + + settings_kv['disabled_plugins'] = ','.join(self.plugins.disabled) + settings_kv['enabled_plugins'] = ','.join(self.plugins.enabled) + + return urlencode(settings_kv) + + def parse_dict(self, input_data): for user_setting_name, user_setting in input_data.items(): if user_setting_name in self.key_value_settings: self.key_value_settings[user_setting_name].parse(user_setting) |