|
@@ -1,5 +1,6 @@
|
1
|
1
|
from searx import settings, autocomplete
|
2
|
2
|
from searx.languages import language_codes as languages
|
|
3
|
+from searx.url_utils import urlencode
|
3
|
4
|
|
4
|
5
|
|
5
|
6
|
COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years
|
|
@@ -232,7 +233,7 @@ class PluginsSetting(SwitchableSetting):
|
232
|
233
|
|
233
|
234
|
|
234
|
235
|
class Preferences(object):
|
235
|
|
- """Stores, validates and saves preferences to cookies"""
|
|
236
|
+ """Validates and saves preferences to cookies"""
|
236
|
237
|
|
237
|
238
|
def __init__(self, themes, categories, engines, plugins):
|
238
|
239
|
super(Preferences, self).__init__()
|
|
@@ -247,19 +248,40 @@ class Preferences(object):
|
247
|
248
|
'image_proxy': MapSetting(settings['server']['image_proxy'],
|
248
|
249
|
map={'': settings['server']['image_proxy'],
|
249
|
250
|
'0': False,
|
250
|
|
- '1': True}),
|
|
251
|
+ '1': True,
|
|
252
|
+ 'True': True,
|
|
253
|
+ 'False': False}),
|
251
|
254
|
'method': EnumStringSetting('POST', choices=('GET', 'POST')),
|
252
|
255
|
'safesearch': MapSetting(settings['search']['safe_search'], map={'0': 0,
|
253
|
256
|
'1': 1,
|
254
|
257
|
'2': 2}),
|
255
|
258
|
'theme': EnumStringSetting(settings['ui']['default_theme'], choices=themes),
|
256
|
|
- 'results_on_new_tab': MapSetting(False, map={'0': False, '1': True})}
|
|
259
|
+ 'results_on_new_tab': MapSetting(False, map={'0': False,
|
|
260
|
+ '1': True,
|
|
261
|
+ 'False': False,
|
|
262
|
+ 'True': True})}
|
257
|
263
|
|
258
|
264
|
self.engines = EnginesSetting('engines', choices=engines)
|
259
|
265
|
self.plugins = PluginsSetting('plugins', choices=plugins)
|
260
|
266
|
self.unknown_params = {}
|
261
|
267
|
|
262
|
|
- def parse_cookies(self, input_data):
|
|
268
|
+ def get_as_url_params(self):
|
|
269
|
+ settings_kv = {}
|
|
270
|
+ for k, v in self.key_value_settings.items():
|
|
271
|
+ if isinstance(v, MultipleChoiceSetting):
|
|
272
|
+ settings_kv[k] = ','.join(v.get_value())
|
|
273
|
+ else:
|
|
274
|
+ settings_kv[k] = v.get_value()
|
|
275
|
+
|
|
276
|
+ settings_kv['disabled_engines'] = ','.join(self.engines.disabled)
|
|
277
|
+ settings_kv['enabled_engines'] = ','.join(self.engines.enabled)
|
|
278
|
+
|
|
279
|
+ settings_kv['disabled_plugins'] = ','.join(self.plugins.disabled)
|
|
280
|
+ settings_kv['enabled_plugins'] = ','.join(self.plugins.enabled)
|
|
281
|
+
|
|
282
|
+ return urlencode(settings_kv)
|
|
283
|
+
|
|
284
|
+ def parse_dict(self, input_data):
|
263
|
285
|
for user_setting_name, user_setting in input_data.items():
|
264
|
286
|
if user_setting_name in self.key_value_settings:
|
265
|
287
|
self.key_value_settings[user_setting_name].parse(user_setting)
|