diff options
author | Alexandre Flament <alex@al-f.net> | 2020-09-22 18:03:42 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-09-22 18:59:51 +0200 |
commit | 678699beaf97184a9059b0c6514b1a51c7e6dfd0 (patch) | |
tree | cfad322e7aecb30a4ffb84f0c30fbbcaadafb642 /searx/webapp.py | |
parent | d5b5e48f04e2e156cb975c136ec4b179b170509a (diff) | |
download | searxng-678699beaf97184a9059b0c6514b1a51c7e6dfd0.tar.gz searxng-678699beaf97184a9059b0c6514b1a51c7e6dfd0.zip |
[mod] searx/webadapter.py: add get_selected_categories share common code with get_search_query_from_webapp
Update searx/webapp.py to use get_selected_categories
Close #2142
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-x | searx/webapp.py | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/searx/webapp.py b/searx/webapp.py index 2a763292d..119f9f3b7 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -67,7 +67,7 @@ from searx.webutils import ( get_static_files, get_result_templates, get_themes, prettify_url, new_hmac ) -from searx.webadapter import get_search_query_from_webapp +from searx.webadapter import get_search_query_from_webapp, get_selected_categories from searx.utils import html_to_text, gen_useragent, dict_subset, match_language from searx.version import VERSION_STRING from searx.languages import language_codes as languages @@ -355,25 +355,6 @@ def render(template_name, override_theme=None, **kwargs): _get_ordered_categories() if x in enabled_categories] - if 'all_categories' not in kwargs: - kwargs['all_categories'] = _get_ordered_categories() - - if 'selected_categories' not in kwargs: - kwargs['selected_categories'] = [] - for arg in request.args: - if arg.startswith('category_'): - c = arg.split('_', 1)[1] - if c in categories: - kwargs['selected_categories'].append(c) - - if not kwargs['selected_categories']: - cookie_categories = request.preferences.get_value('categories') - for ccateg in cookie_categories: - kwargs['selected_categories'].append(ccateg) - - if not kwargs['selected_categories']: - kwargs['selected_categories'] = ['general'] - if 'autocomplete' not in kwargs: kwargs['autocomplete'] = request.preferences.get_value('autocomplete') @@ -532,6 +513,7 @@ def index_error(output_format, error_message): request.errors.append(gettext('search error')) return render( 'index.html', + selected_categories=get_selected_categories(request.form, request.preferences), ) @@ -553,6 +535,7 @@ def index(): if output_format == 'html': return render( 'index.html', + selected_categories=get_selected_categories(request.form, request.preferences), ) else: return index_error(output_format, 'No query'), 400 @@ -833,6 +816,8 @@ def preferences(): # end of stats return render('preferences.html', + selected_categories=get_selected_categories(request.form, request.preferences), + all_categories=_get_ordered_categories(), locales=settings['locales'], current_locale=request.preferences.get_value("locale"), image_proxy=image_proxy, |