Browse Source

[enh] make custom oscar option configurable from url

Adam Tauber 7 years ago
parent
commit
e060aedc16

+ 4 - 0
searx/preferences.py

@@ -305,6 +305,8 @@ class Preferences(object):
             elif user_setting_name == 'disabled_plugins':
                 self.plugins.parse_cookie((input_data.get('disabled_plugins', ''),
                                            input_data.get('enabled_plugins', '')))
+            else:
+                self.unknown_params[user_setting_name] = user_setting
 
     def parse_form(self, input_data):
         disabled_engines = []
@@ -329,6 +331,8 @@ class Preferences(object):
     def get_value(self, user_setting_name):
         if user_setting_name in self.key_value_settings:
             return self.key_value_settings[user_setting_name].get_value()
+        if user_setting_name in self.unknown_params:
+            return self.unknown_params[user_setting_name]
 
     def save(self, resp):
         for user_setting_name, user_setting in self.key_value_settings.items():

+ 2 - 2
searx/templates/oscar/base.html

@@ -13,8 +13,8 @@
     <title>{% block title %}{% endblock %}{{ instance_name }}</title>
 
     <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css" />
-    {% if cookies['oscar-style'] %}
-        <link rel="stylesheet" href="{{ url_for('static', filename='css/'+cookies['oscar-style']+'.min.css') }}" type="text/css" />
+    {% if preferences.get_value('oscar-style') %}
+        <link rel="stylesheet" href="{{ url_for('static', filename='css/'+preferences.get_value('oscar-style')+'.min.css') }}" type="text/css" />
     {% else %}
         <link rel="stylesheet" href="{{ url_for('static', filename='css/logicodev.min.css') }}" type="text/css" />
     {% endif %}

+ 2 - 2
searx/templates/oscar/preferences.html

@@ -106,8 +106,8 @@
                     {{ preferences_item_header(_('Choose style for this theme'), _('Style'), rtl) }}
                         <select class="form-control" name='oscar-style'>
                             <option value="logicodev" >Logicodev</option>
-                            <option value="pointhi" {% if cookies['oscar-style'] == 'pointhi' %}selected="selected"{% endif %}>Pointhi</option>
-                            <option value="logicodev-dark" {% if cookies['oscar-style'] == 'logicodev-dark' %}selected="selected"{% endif %}>Logicodev dark</option>
+                            <option value="pointhi" {% if preferences.get_value('oscar-style') == 'pointhi' %}selected="selected"{% endif %}>Pointhi</option>
+                            <option value="logicodev-dark" {% if preferences.get_value('oscar-style') == 'logicodev-dark' %}selected="selected"{% endif %}>Logicodev dark</option>
                         </select>
                     {{ preferences_item_footer(_('Choose style for this theme'), _('Style'), rtl) }}
 

+ 2 - 0
searx/webapp.py

@@ -376,6 +376,8 @@ def render(template_name, override_theme=None, **kwargs):
 
     kwargs['unicode'] = unicode
 
+    kwargs['preferences'] = request.preferences
+
     kwargs['scripts'] = set()
     for plugin in request.user_plugins:
         for script in plugin.js_dependencies: