forked from Ponysearch/Ponysearch
[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:
parent
4ac6b5d32d
commit
ab90e2ac49
4 changed files with 13 additions and 4 deletions
|
@ -45,6 +45,9 @@ ENGINE_DEFAULT_ARGS = {
|
||||||
"display_error_messages": True,
|
"display_error_messages": True,
|
||||||
"tokens": [],
|
"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`"""
|
"""Defaults for the namespace of an engine module, see :py:func:`load_engine`"""
|
||||||
|
|
||||||
categories = {'general': []}
|
categories = {'general': []}
|
||||||
|
@ -114,6 +117,9 @@ def load_engine(engine_data):
|
||||||
|
|
||||||
set_loggers(engine, engine_name)
|
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
|
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())
|
return (group[0] == DEFAULT_GROUP_NAME, group[0].lower())
|
||||||
|
|
||||||
def get_group(eng):
|
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 non_tab_engines[0] if len(non_tab_engines) > 0 else DEFAULT_GROUP_NAME
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -298,7 +298,7 @@
|
||||||
<div class="tab-pane active_if_nojs" id="tab_engine">
|
<div class="tab-pane active_if_nojs" id="tab_engine">
|
||||||
<!-- Nav tabs -->
|
<!-- Nav tabs -->
|
||||||
<ul class="nav nav-tabs nav-justified hide_if_nojs" role="tablist">
|
<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>
|
<li{% if loop.first %} class="active"{% endif %}><a href="#tab_engine_{{ categ|replace(' ', '_') }}" role="tab" data-toggle="tab">{{ _(categ) }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -317,7 +317,7 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for categ in categories_as_tabs %}
|
{% for categ in categories_as_tabs + [OTHER_CATEGORY] %}
|
||||||
<noscript><label>{{ _(categ) }}</label>
|
<noscript><label>{{ _(categ) }}</label>
|
||||||
</noscript>
|
</noscript>
|
||||||
<div class="tab-pane{% if loop.first %} active{% endif %} active_if_nojs" id="tab_engine_{{ categ|replace(' ', '_') }}">
|
<div class="tab-pane{% if loop.first %} active{% endif %} active_if_nojs" id="tab_engine_{{ categ|replace(' ', '_') }}">
|
||||||
|
|
|
@ -274,7 +274,7 @@
|
||||||
{{ tab_header('maintab', 'engines', _('Engines')) }}
|
{{ tab_header('maintab', 'engines', _('Engines')) }}
|
||||||
<p>{{ _('Currently used search engines') }}</p>
|
<p>{{ _('Currently used search engines') }}</p>
|
||||||
{{ tabs_open() }}
|
{{ tabs_open() }}
|
||||||
{% for categ in categories_as_tabs %}
|
{% for categ in categories_as_tabs + [OTHER_CATEGORY] %}
|
||||||
{{ tab_header('enginetab', 'category' + categ, _(categ)) }}
|
{{ tab_header('enginetab', 'category' + categ, _(categ)) }}
|
||||||
<div class="scrollx">
|
<div class="scrollx">
|
||||||
<table class="striped">
|
<table class="striped">
|
||||||
|
|
|
@ -59,6 +59,7 @@ from searx.settings_defaults import OUTPUT_FORMATS
|
||||||
from searx.settings_loader import get_default_settings_path
|
from searx.settings_loader import get_default_settings_path
|
||||||
from searx.exceptions import SearxParameterException
|
from searx.exceptions import SearxParameterException
|
||||||
from searx.engines import (
|
from searx.engines import (
|
||||||
|
OTHER_CATEGORY,
|
||||||
DEFAULT_GROUP_NAME,
|
DEFAULT_GROUP_NAME,
|
||||||
categories,
|
categories,
|
||||||
engines,
|
engines,
|
||||||
|
@ -182,6 +183,7 @@ _category_names = (
|
||||||
gettext('software wikis'),
|
gettext('software wikis'),
|
||||||
gettext('web'),
|
gettext('web'),
|
||||||
gettext(DEFAULT_GROUP_NAME),
|
gettext(DEFAULT_GROUP_NAME),
|
||||||
|
gettext(OTHER_CATEGORY),
|
||||||
)
|
)
|
||||||
|
|
||||||
_simple_style = (gettext('auto'), gettext('light'), gettext('dark'))
|
_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['theme'] = get_current_theme_name(override=override_theme)
|
||||||
kwargs['categories_as_tabs'] = settings['categories_as_tabs']
|
kwargs['categories_as_tabs'] = settings['categories_as_tabs']
|
||||||
kwargs['categories'] = _get_enable_categories(categories.keys())
|
kwargs['categories'] = _get_enable_categories(categories.keys())
|
||||||
|
kwargs['OTHER_CATEGORY'] = OTHER_CATEGORY
|
||||||
|
|
||||||
# i18n
|
# i18n
|
||||||
kwargs['language_codes'] = [l for l in languages if l[0] in settings['search']['languages']]
|
kwargs['language_codes'] = [l for l in languages if l[0] in settings['search']['languages']]
|
||||||
|
|
Loading…
Reference in a new issue