summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-07-23 18:26:43 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2023-04-10 09:22:21 +0200
commit7d17d37ac718e47406ab7af61a2dceb6635b77f9 (patch)
treec59f7aefb4ac0cb0a6141400ac4b09fa71992a1a /searx/webapp.py
parentac040fda3298f1c0de4ed42a7f9aceaaa16e322b (diff)
downloadsearxng-7d17d37ac718e47406ab7af61a2dceb6635b77f9.tar.gz
searxng-7d17d37ac718e47406ab7af61a2dceb6635b77f9.zip
[fix] don't show a category if there is no active engine in
When deactivate all the engines of a category, this category should disappeare. This feature has been lost in commit 8e9ad1cc. For better readability, webapp.get_enabled_categories() has been rewritten with identical functionality. Related: - https://github.com/searxng/searxng/issues/1020 - https://github.com/searxng/searxng/issues/1604 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 64a5c8452..388b28c38 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -373,16 +373,15 @@ def get_translations():
}
-def _get_enable_categories(all_categories: Iterable[str]):
- disabled_engines = request.preferences.engines.get_disabled()
- enabled_categories = set(
- # pylint: disable=consider-using-dict-items
- category
- for engine_name in engines
- for category in engines[engine_name].categories
- if (engine_name, category) not in disabled_engines
- )
- return [x for x in all_categories if x in enabled_categories]
+def get_enabled_categories(category_names: Iterable[str]):
+ """The categories in ``category_names```for which there is no active engine
+ are filtered out and a reduced list is returned."""
+
+ enabled_engines = [item[0] for item in request.preferences.engines.get_enabled()]
+ enabled_categories = set()
+ for engine_name in enabled_engines:
+ enabled_categories.update(engines[engine_name].categories)
+ return [x for x in category_names if x in enabled_categories]
def get_pretty_url(parsed_url: urllib.parse.ParseResult):
@@ -434,7 +433,7 @@ def render(template_name: str, **kwargs):
kwargs['theme'] = request.preferences.get_value('theme')
kwargs['method'] = request.preferences.get_value('method')
kwargs['categories_as_tabs'] = list(settings['categories_as_tabs'].keys())
- kwargs['categories'] = _get_enable_categories(categories.keys())
+ kwargs['categories'] = get_enabled_categories(settings['categories_as_tabs'].keys())
kwargs['DEFAULT_CATEGORY'] = DEFAULT_CATEGORY
# i18n