From ab90e2ac49778153409397d4a2c34e9051963a0f Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Tue, 28 Dec 2021 16:12:54 +0100 Subject: [PATCH] [enh] show categories not in any tab category in "Other" preferences tab Previously we didn't have a good place to put search engines that don't fit into any of the tab categories. This commit automatically puts search engines that don't belong to any tab category in an "other" category, that is only displayed in the user preferences (and not above search results). --- searx/engines/__init__.py | 8 +++++++- searx/templates/oscar/preferences.html | 4 ++-- searx/templates/simple/preferences.html | 2 +- searx/webapp.py | 3 +++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index 8d49bae8a..9472186bf 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -45,6 +45,9 @@ ENGINE_DEFAULT_ARGS = { "display_error_messages": True, "tokens": [], } +# set automatically when an engine does not have any tab category +OTHER_CATEGORY = 'other' + """Defaults for the namespace of an engine module, see :py:func:`load_engine`""" categories = {'general': []} @@ -114,6 +117,9 @@ def load_engine(engine_data): set_loggers(engine, engine_name) + if not any(cat in settings['categories_as_tabs'] for cat in engine.categories): + engine.categories.append(OTHER_CATEGORY) + return engine @@ -274,7 +280,7 @@ def group_engines_in_tab(engines): # pylint: disable=redefined-outer-name return (group[0] == DEFAULT_GROUP_NAME, group[0].lower()) def get_group(eng): - non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs']] + non_tab_engines = [c for c in eng.categories if c not in settings['categories_as_tabs'] + [OTHER_CATEGORY]] return non_tab_engines[0] if len(non_tab_engines) > 0 else DEFAULT_GROUP_NAME return [ diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index 810e6f072..341c203b0 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -298,7 +298,7 @@
@@ -317,7 +317,7 @@

- {% for categ in categories_as_tabs %} + {% for categ in categories_as_tabs + [OTHER_CATEGORY] %}
diff --git a/searx/templates/simple/preferences.html b/searx/templates/simple/preferences.html index b4676d131..bec478f26 100644 --- a/searx/templates/simple/preferences.html +++ b/searx/templates/simple/preferences.html @@ -274,7 +274,7 @@ {{ tab_header('maintab', 'engines', _('Engines')) }}

{{ _('Currently used search engines') }}

{{ tabs_open() }} - {% for categ in categories_as_tabs %} + {% for categ in categories_as_tabs + [OTHER_CATEGORY] %} {{ tab_header('enginetab', 'category' + categ, _(categ)) }}
diff --git a/searx/webapp.py b/searx/webapp.py index 9ce7b9d5a..c0467932e 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -59,6 +59,7 @@ from searx.settings_defaults import OUTPUT_FORMATS from searx.settings_loader import get_default_settings_path from searx.exceptions import SearxParameterException from searx.engines import ( + OTHER_CATEGORY, DEFAULT_GROUP_NAME, categories, engines, @@ -182,6 +183,7 @@ _category_names = ( gettext('software wikis'), gettext('web'), gettext(DEFAULT_GROUP_NAME), + gettext(OTHER_CATEGORY), ) _simple_style = (gettext('auto'), gettext('light'), gettext('dark')) @@ -439,6 +441,7 @@ def render(template_name, override_theme=None, **kwargs): kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['categories_as_tabs'] = settings['categories_as_tabs'] kwargs['categories'] = _get_enable_categories(categories.keys()) + kwargs['OTHER_CATEGORY'] = OTHER_CATEGORY # i18n kwargs['language_codes'] = [l for l in languages if l[0] in settings['search']['languages']]