diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-25 17:12:02 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarit.de> | 2020-03-25 17:12:02 +0100 |
commit | ace7d30aed0bdff07e97cdb3900c38633877cdcd (patch) | |
tree | 04eb8e92af63d7d4d65ed2cfa9d075c338894d73 | |
parent | d471ec86dd72cfae80bdaf72b1ed266b1a8cada7 (diff) | |
download | searxng-ace7d30aed0bdff07e97cdb3900c38633877cdcd.tar.gz searxng-ace7d30aed0bdff07e97cdb3900c38633877cdcd.zip |
webapp.py: partial code review (no functional change)
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
-rwxr-xr-x | searx/webapp.py | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index c6b52d6ab..3af5c57b4 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -958,34 +958,47 @@ def clear_cookies(): @app.route('/config') def config(): - return jsonify({'categories': list(categories.keys()), - 'engines': [{'name': name, - 'categories': engine.categories, - 'shortcut': engine.shortcut, - 'enabled': not engine.disabled, - 'paging': engine.paging, - 'language_support': engine.language_support, - 'supported_languages': - list(engine.supported_languages.keys()) - if isinstance(engine.supported_languages, dict) - else engine.supported_languages, - 'safesearch': engine.safesearch, - 'time_range_support': engine.time_range_support, - 'timeout': engine.timeout} - for name, engine in engines.items() if request.preferences.validate_token(engine)], - 'plugins': [{'name': plugin.name, - 'enabled': plugin.default_on} - for plugin in plugins], - 'instance_name': settings['general']['instance_name'], - 'locales': settings['locales'], - 'default_locale': settings['ui']['default_locale'], - 'autocomplete': settings['search']['autocomplete'], - 'safe_search': settings['search']['safe_search'], - 'default_theme': settings['ui']['default_theme'], - 'version': VERSION_STRING, - 'doi_resolvers': [r for r in settings['doi_resolvers']], - 'default_doi_resolver': settings['default_doi_resolver'], - }) + """Return configuration in JSON format.""" + _engines = [] + for name, engine in engines.items(): + if not request.preferences.validate_token(engine): + continue + + supported_languages = engine.supported_languages + if isinstance(engine.supported_languages, dict): + supported_languages = list(engine.supported_languages.keys()) + + _engines.append({ + 'name': name, + 'categories': engine.categories, + 'shortcut': engine.shortcut, + 'enabled': not engine.disabled, + 'paging': engine.paging, + 'language_support': engine.language_support, + 'supported_languages': supported_languages, + 'safesearch': engine.safesearch, + 'time_range_support': engine.time_range_support, + 'timeout': engine.timeout + }) + + _plugins = [] + for _ in plugins: + _plugins.append({'name': _.name, 'enabled': _.default_on}) + + return jsonify({ + 'categories': list(categories.keys()), + 'engines': _engines, + 'plugins': _plugins, + 'instance_name': settings['general']['instance_name'], + 'locales': settings['locales'], + 'default_locale': settings['ui']['default_locale'], + 'autocomplete': settings['search']['autocomplete'], + 'safe_search': settings['search']['safe_search'], + 'default_theme': settings['ui']['default_theme'], + 'version': VERSION_STRING, + 'doi_resolvers': [r for r in settings['doi_resolvers']], + 'default_doi_resolver': settings['default_doi_resolver'], + }) @app.errorhandler(404) |