From f83b64270c6c8cff336889b93fdf6b6e3f20ffa2 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 1 Jun 2021 16:21:56 +0200 Subject: [PATCH 1/2] [mod] oscar theme /preferences: reorganize the preferences close #115 --- searx/plugins/__init__.py | 2 + searx/plugins/hash_plugin.py | 3 + searx/plugins/self_info.py | 4 +- searx/templates/oscar/preferences.html | 280 ++++++++++++++----------- tests/robot/__init__.py | 1 + 5 files changed, 162 insertions(+), 128 deletions(-) diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index 22f475875..f9fb3aa58 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -70,6 +70,8 @@ class PluginStore(): if not hasattr(plugin, plugin_attr) or not isinstance(getattr(plugin, plugin_attr), plugin_attr_type): setattr(plugin, plugin_attr, plugin_attr_type()) plugin.id = plugin.name.replace(' ', '_') + if not hasattr(plugin, 'preference_section'): + plugin.preference_section = 'general' self.plugins.append(plugin) def call(self, ordered_plugin_list, plugin_type, request, *args, **kwargs): diff --git a/searx/plugins/hash_plugin.py b/searx/plugins/hash_plugin.py index 1d3baaede..edb91dd8e 100644 --- a/searx/plugins/hash_plugin.py +++ b/searx/plugins/hash_plugin.py @@ -23,6 +23,9 @@ import re name = "Hash plugin" description = gettext("Converts strings to different hash digests.") default_on = True +preference_section = 'query' +query_keywords = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'] +query_examples = 'sha512 The quick brown fox jumps over the lazy dog' parser_re = re.compile('(md5|sha1|sha224|sha256|sha384|sha512) (.*)', re.I) diff --git a/searx/plugins/self_info.py b/searx/plugins/self_info.py index 4fdfb4288..053899483 100644 --- a/searx/plugins/self_info.py +++ b/searx/plugins/self_info.py @@ -19,7 +19,9 @@ import re name = gettext('Self Informations') description = gettext('Displays your IP if the query is "ip" and your user agent if the query contains "user agent".') default_on = True - +preference_section = 'query' +query_keywords = ['user-agent'] +query_examples = '' # Self User Agent regex p = re.compile('.*user[ -]agent.*', re.IGNORECASE) diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index 352b90eed..46b4fdb69 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -76,6 +76,16 @@ {%- endif -%} {%- endmacro -%} +{%- macro plugin_of_category(plugin_category) -%} +{%- for plugin in plugins -%} + {%- if plugin.preference_section == plugin_category -%} + {{- preferences_item_header(_(plugin.description), _(plugin.name), rtl, 'plugin_' + plugin.id) -}} + {{- checkbox_toggle('plugin_' + plugin.id, plugin.id not in allowed_plugins) -}} + {{- preferences_item_footer(_(plugin.description), _(plugin.name), rtl) -}} + {%- endif -%} +{%- endfor -%} +{% endmacro %} + {%- block title %}{{ _('preferences') }} - {% endblock -%} {% block content %} @@ -88,9 +98,10 @@ @@ -125,53 +136,6 @@ {{ preferences_item_footer(language_info, language_label, rtl) }} {% endif %} - {% if 'locale' not in locked_preferences %} - {% set locale_label = _('Interface language') %} - {% set locale_info = _('Change the language of the layout') %} - {{ preferences_item_header(locale_info, locale_label, rtl, 'locale') }} - - {{ preferences_item_footer(locale_info, locale_label, rtl) }} - {% endif %} - - {% if 'autocomplete' not in locked_preferences %} - {% set autocomplete_label = _('Autocomplete') %} - {% set autocomplete_info = _('Find stuff as you type') %} - {{ preferences_item_header(autocomplete_info, autocomplete_label, rtl, 'autocomplete') }} - - {{ preferences_item_footer(autocomplete_info, autocomplete_label, rtl) }} - {% endif %} - - {% if 'image_proxy' not in locked_preferences %} - {% set image_proxy_label = _('Image proxy') %} - {% set image_proxy_info = _('Proxying image results through searx') %} - {{ preferences_item_header(image_proxy_info, image_proxy_label, rtl, 'image_proxy') }} - - {{ preferences_item_footer(image_proxy_info, image_proxy_label, rtl) }} - {% endif %} - - {% if 'method' not in locked_preferences %} - {% set method_label = _('Method') %} - {% set method_info = _('Change how forms are submited, learn more about request methods') %} - {{ preferences_item_header(method_info, method_label, rtl, 'method') }} - - {{ preferences_item_footer(method_info, method_label, rtl) }} - {% endif %} - {% if 'safesearch' not in locked_preferences %} {% set safesearch_label = _('SafeSearch') %} {% set safesearch_info = _('Filter content') %} @@ -184,47 +148,20 @@ {{ preferences_item_footer(safesearch_info, safesearch_label, rtl) }} {% endif %} - {% if 'theme' not in locked_preferences %} - {% set theme_label = _('Themes') %} - {% set theme_info = _('Change searx layout') %} - {{ preferences_item_header(theme_info, theme_label, rtl, 'theme') }} - + + {% for backend in autocomplete_backends %} + {% endfor %} - {{ preferences_item_footer(theme_info, theme_label, rtl) }} - {% endif %} - - {% if 'oscar-style' not in locked_preferences %} - {{ preferences_item_header(_('Choose style for this theme'), _('Style'), rtl, 'oscar_style') }} - - {{ preferences_item_footer(_('Choose style for this theme'), _('Style'), rtl) }} - {% endif %} - - {% if 'results_on_new_tab' not in locked_preferences %} - {% set label = _('Results on new tabs') %} - {% set info = _('Open result links on new browser tabs') %} - {{ preferences_item_header(info, label, rtl, 'results_on_new_tab') }} - - {{ preferences_item_footer(info, label, rtl) }} + {{ preferences_item_footer(autocomplete_info, autocomplete_label, rtl) }} {% endif %} - {% set label = _('Show advanced settings') %} - {% set info = _('Show advanced settings panel in the home page by default') %} - {{ preferences_item_header(info, label, rtl, 'advanced_search') }} - - {{ preferences_item_footer(info, label, rtl) }} + {{ plugin_of_category('general' )}} {% if 'doi_resolver' not in locked_preferences %} {% set label = _('Open Access DOI resolver') %} @@ -240,6 +177,8 @@ {{ preferences_item_footer(info, label, rtl) }} {% endif %} + {{ plugin_of_category('onion' )}} + {% set label = _('Engine tokens') %} {% set info = _('Access tokens for private engines') %} {{ preferences_item_header(info, label, rtl, 'tokens') }} @@ -344,61 +283,148 @@ {% endfor %} -
+
- {% for plugin in plugins %} - {% if plugin.preference_section != 'onions' %} -
-
-

{{ _(plugin.name) }}

-
-
-
-
-
- {{ checkbox_toggle('plugin_' + plugin.id, plugin.id not in allowed_plugins) }} -
-
-
-
+ {% if 'locale' not in locked_preferences %} + {% set locale_label = _('Interface language') %} + {% set locale_info = _('Change the language of the layout') %} + {{ preferences_item_header(locale_info, locale_label, rtl, 'locale') }} + + {{ preferences_item_footer(locale_info, locale_label, rtl) }} {% endif %} - {% endfor %} + + {% if 'theme' not in locked_preferences %} + {% set theme_label = _('Themes') %} + {% set theme_info = _('Change searx layout') %} + {{ preferences_item_header(theme_info, theme_label, rtl, 'theme') }} + + {{ preferences_item_footer(theme_info, theme_label, rtl) }} + {% endif %} + + {% if 'oscar-style' not in locked_preferences %} + {{ preferences_item_header(_('Choose style for this theme'), _('Style'), rtl, 'oscar_style') }} + + {{ preferences_item_footer(_('Choose style for this theme'), _('Style'), rtl) }} + {% endif %} + + {% set label = _('Show advanced settings') %} + {% set info = _('Show advanced settings panel in the home page by default') %} + {{ preferences_item_header(info, label, rtl, 'advanced_search') }} + + {{ preferences_item_footer(info, label, rtl) }} + + {% if 'results_on_new_tab' not in locked_preferences %} + {% set label = _('Results on new tabs') %} + {% set info = _('Open result links on new browser tabs') %} + {{ preferences_item_header(info, label, rtl, 'results_on_new_tab') }} + + {{ preferences_item_footer(info, label, rtl) }} + {% endif %} + + {{ plugin_of_category('ui' )}}
+
+ +
+
+ {% if 'method' not in locked_preferences %} + {% set method_label = _('Method') %} + {% set method_info = _('Change how forms are submited, learn more about request methods') %} + {{ preferences_item_header(method_info, method_label, rtl, 'method') }} + + {{ preferences_item_footer(method_info, method_label, rtl) }} + {% endif %} - {% if answerers %} -
+ {% if 'image_proxy' not in locked_preferences %} + {% set image_proxy_label = _('Image proxy') %} + {% set image_proxy_info = _('Proxying image results through searx') %} + {{ preferences_item_header(image_proxy_info, image_proxy_label, rtl, 'image_proxy') }} + + {{ preferences_item_footer(image_proxy_info, image_proxy_label, rtl) }} + {% endif %} + + {{ plugin_of_category('privacy' )}} +
+
+
+
-

- {{ _('This is the list of searx\'s instant answering modules.') }} -

+ {% if answerers %} - - {{ _('Name') }} - {{ _('Keywords') }} - {{ _('Description') }} - {{ _('Examples') }} - - - {% for answerer in answerers %} - - - - - - - {% endfor %} + + + {{ _('Allow') }} + {{ _('Keywords') }} + {{ _('Name') }} + {{ _('Description') }} + {{ _('Examples') }} + + + + + + {% for answerer in answerers %} + + + + + + + + {% endfor %} + + + + + {%- for plugin in plugins -%} + {%- if plugin.preference_section == 'query' -%} + + + + + + + + {%- endif -%} + {%- endfor -%} +
{{ answerer.info.name }}{{ answerer.keywords|join(', ') }}{{ answerer.info.description }}{{ answerer.info.examples|join(', ') }}
{{ _('This is the list of searx\'s instant answering modules.') }}
{{ answerer.keywords|join(', ') }}{{ answerer.info.name }}{{ answerer.info.description }}{{ answerer.info.examples|join(', ') }}
{{ _('This is the list of plugins.') }}
{{- checkbox_toggle('plugin_' + plugin.id, plugin.id not in allowed_plugins) -}}{{ plugin.query_keywords|join(', ') }}{{ _(plugin.name) }}{{ _(plugin.description) }}{{ plugin.query_examples }}
+ {% endif %}
- {% endif %} -
-
- - - - - - -
- -
-

- - -

-
- - {% for categ in all_categories %} - -
-
-
-
- - - {% if not rtl %} - - - - - - - - - - {% else %} - - - - - - - - - - {% endif %} - - {% for search_engine in engines_by_category[categ] %} - {% if not search_engine.private %} - - {% if not rtl %} - - - - - - - {{ engine_time(search_engine.name, 'text-right') }} - - {{ engine_reliability(search_engine.name, 'text-right ') }} - {% else %} - {{ engine_reliability(search_engine.name, 'text-left') }} - - {{ engine_time(search_engine.name, 'text-left') }} - - - - - - - {% endif %} - - {% endif %} - {% endfor %} -
{{ _("Allow") }}{{ _("Engine name") }}{{ _("Shortcut") }}{{ _("Selected language") }}{{ _("SafeSearch") }}{{ _("Time range") }}{{ _("Response time") }}{{ _("Max time") }}{{ _("Reliablity") }}{{ _("Reliablity") }}{{ _("Max time") }}{{ _("Response time") }}{{ _("Time range") }}{{ _("SafeSearch") }}{{ _("Selected language") }}{{ _("Shortcut") }}{{ _("Engine name") }}{{ _("Allow") }}
- {{- checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) -}} - - {%- if search_engine.enable_http %}{{ icon('exclamation-sign', 'No HTTPS') }}{% endif -%} - {{- search_engine.name -}} - {{- engine_about(search_engine, 'tooltip_' + categ + '_' + search_engine.name) -}} - {{ shortcuts[search_engine.name] }}{{ support_toggle(supports[search_engine.name]['supports_selected_language']) }}{{ support_toggle(supports[search_engine.name]['safesearch']) }}{{ support_toggle(supports[search_engine.name]['time_range_support']) }}{% if stats[search_engine.name]['warn_timeout'] %}{{ icon('exclamation-sign') }} {% endif %}{{ search_engine.timeout }}{{ search_engine.timeout }}{% if stats[search_engine.name]['warn_time'] %} {{ icon('exclamation-sign')}}{% endif %}{{ support_toggle(supports[search_engine.name]['time_range_support']) }}{{ support_toggle(supports[search_engine.name]['safesearch']) }}{{ support_toggle(supports[search_engine.name]['supports_selected_language']) }}{{ shortcuts[search_engine.name] }}{% if search_engine.enable_http %}{{ icon('exclamation-sign', 'No HTTPS') }}{% endif %}{{ search_engine.name }}{{ engine_about(search_engine) }} - {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }} -
-
-
-
-
- {% endfor %} -
-
+
+ + + + + + +
+ +
+

+ + +

+
+ + {% for categ in all_categories %} + +
+
+
+
+ + + {% if not rtl %} + + + + + + + + + + {% else %} + + + + + + + + + + {% endif %} + + {% for search_engine in engines_by_category[categ] %} + {% if not search_engine.private %} + + {% if not rtl %} + + + + + + + {{ engine_time(search_engine.name, 'text-right') }} + + {{ engine_reliability(search_engine.name, 'text-right ') }} + {% else %} + {{ engine_reliability(search_engine.name, 'text-left') }} + + {{ engine_time(search_engine.name, 'text-left') }} + + + + + + + {% endif %} + + {% endif %} + {% endfor %} +
{{ _("Allow") }}{{ _("Engine name") }}{{ _("Shortcut") }}{{ _("Selected language") }}{{ _("SafeSearch") }}{{ _("Time range") }}{{ _("Response time") }}{{ _("Max time") }}{{ _("Reliablity") }}{{ _("Reliablity") }}{{ _("Max time") }}{{ _("Response time") }}{{ _("Time range") }}{{ _("SafeSearch") }}{{ _("Selected language") }}{{ _("Shortcut") }}{{ _("Engine name") }}{{ _("Allow") }}
+ {{- checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) -}} + + {%- if search_engine.enable_http %}{{ icon('exclamation-sign', 'No HTTPS') }}{% endif -%} + {{- search_engine.name -}} + {{- engine_about(search_engine, 'tooltip_' + categ + '_' + search_engine.name) -}} + {{ shortcuts[search_engine.name] }}{{ support_toggle(supports[search_engine.name]['supports_selected_language']) }}{{ support_toggle(supports[search_engine.name]['safesearch']) }}{{ support_toggle(supports[search_engine.name]['time_range_support']) }}{% if stats[search_engine.name]['warn_timeout'] %}{{ icon('exclamation-sign') }} {% endif %}{{ search_engine.timeout }}{{ search_engine.timeout }}{% if stats[search_engine.name]['warn_time'] %} {{ icon('exclamation-sign')}}{% endif %}{{ support_toggle(supports[search_engine.name]['time_range_support']) }}{{ support_toggle(supports[search_engine.name]['safesearch']) }}{{ support_toggle(supports[search_engine.name]['supports_selected_language']) }}{{ shortcuts[search_engine.name] }}{% if search_engine.enable_http %}{{ icon('exclamation-sign', 'No HTTPS') }}{% endif %}{{ search_engine.name }}{{ engine_about(search_engine) }} + {{ checkbox_toggle('engine_' + search_engine.name|replace(' ', '_') + '__' + categ|replace(' ', '_'), (search_engine.name, categ) in disabled_engines) }} +
+
+
+
+
+ {% endfor %} +
+