1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 12:10:11 +01:00

[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).
This commit is contained in:
Martin Fischer 2021-12-28 16:12:54 +01:00
parent 4ac6b5d32d
commit ab90e2ac49
4 changed files with 13 additions and 4 deletions

View File

@ -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 [

View File

@ -298,7 +298,7 @@
<div class="tab-pane active_if_nojs" id="tab_engine">
<!-- Nav tabs -->
<ul class="nav nav-tabs nav-justified hide_if_nojs" role="tablist">
{% for categ in categories_as_tabs %}
{% for categ in categories_as_tabs + [OTHER_CATEGORY] %}
<li{% if loop.first %} class="active"{% endif %}><a href="#tab_engine_{{ categ|replace(' ', '_') }}" role="tab" data-toggle="tab">{{ _(categ) }}</a></li>
{% endfor %}
</ul>
@ -317,7 +317,7 @@
</p>
</div>
{% for categ in categories_as_tabs %}
{% for categ in categories_as_tabs + [OTHER_CATEGORY] %}
<noscript><label>{{ _(categ) }}</label>
</noscript>
<div class="tab-pane{% if loop.first %} active{% endif %} active_if_nojs" id="tab_engine_{{ categ|replace(' ', '_') }}">

View File

@ -274,7 +274,7 @@
{{ tab_header('maintab', 'engines', _('Engines')) }}
<p>{{ _('Currently used search engines') }}</p>
{{ tabs_open() }}
{% for categ in categories_as_tabs %}
{% for categ in categories_as_tabs + [OTHER_CATEGORY] %}
{{ tab_header('enginetab', 'category' + categ, _(categ)) }}
<div class="scrollx">
<table class="striped">

View File

@ -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']]