From b00f77059c93bc91f706b5f0c51f7db752669b09 Mon Sep 17 00:00:00 2001 From: renyhp Date: Sun, 22 Nov 2020 18:00:21 +0100 Subject: [PATCH 1/5] Add preference for displaying advanced settings --- searx/preferences.py | 9 +++++++++ searx/templates/oscar/preferences.html | 9 +++++++++ searx/webapp.py | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/searx/preferences.py b/searx/preferences.py index e5ad6ead7..b37f0104a 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -395,6 +395,15 @@ class Preferences: settings['ui'].get('theme_args', {}).get('oscar_style', 'logicodev'), is_locked('oscar-style'), choices=['', 'logicodev', 'logicodev-dark', 'pointhi']), + 'advanced_search': MapSetting( + settings['ui'].get('advanced_search', False), + map={ + '0': False, + '1': True, + 'False': False, + 'True': True + } + ), } self.engines = EnginesSetting('engines', choices=engines) diff --git a/searx/templates/oscar/preferences.html b/searx/templates/oscar/preferences.html index b596f66d8..bc688dade 100644 --- a/searx/templates/oscar/preferences.html +++ b/searx/templates/oscar/preferences.html @@ -140,6 +140,15 @@ {{ preferences_item_footer(info, label, rtl) }} {% endif %} + {% set label = _('Show advanced settings') %} + {% set info = _('Show advanced settings panel in the home page by default') %} + {{ preferences_item_header(info, label, rtl, 'advanced_search') }} + + {{ preferences_item_footer(info, label, rtl) }} + {% if 'doi_resolver' not in locked_preferences %} {% set label = _('Open Access DOI resolver') %} {% set info = _('Redirect to open-access versions of publications when available (plugin required)') %} diff --git a/searx/webapp.py b/searx/webapp.py index 2a93c3765..c0530a834 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -545,6 +545,9 @@ def index_error(output_format, error_message): def index(): """Render index page.""" + # UI + advanced_search = request.form.get('advanced_search', request.preferences.get_value('advanced_search')) + # redirect to search if there's a query in the request if request.form.get('q'): query = ('?' + request.query_string.decode()) if request.query_string else '' @@ -553,6 +556,7 @@ def index(): return render( 'index.html', selected_categories=get_selected_categories(request.preferences, request.form), + advanced_search=advanced_search, ) From 22489c4b5f927af5d74b3670b917aee0732543cc Mon Sep 17 00:00:00 2001 From: renyhp Date: Mon, 23 Nov 2020 19:13:29 +0100 Subject: [PATCH 2/5] Patch advanced search preferences --- searx/preferences.py | 4 +++- searx/webapp.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/searx/preferences.py b/searx/preferences.py index b37f0104a..a9f16ff78 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -397,11 +397,13 @@ class Preferences: choices=['', 'logicodev', 'logicodev-dark', 'pointhi']), 'advanced_search': MapSetting( settings['ui'].get('advanced_search', False), + is_locked('advanced_search'), map={ '0': False, '1': True, 'False': False, - 'True': True + 'True': True, + 'on': True, } ), } diff --git a/searx/webapp.py b/searx/webapp.py index c0530a834..b1fa84ced 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -546,7 +546,7 @@ def index(): """Render index page.""" # UI - advanced_search = request.form.get('advanced_search', request.preferences.get_value('advanced_search')) + advanced_search = request.preferences.get_value('advanced_search') # redirect to search if there's a query in the request if request.form.get('q'): @@ -611,7 +611,7 @@ def search(): return redirect(result_container.redirect_url) # UI - advanced_search = request.form.get('advanced_search', None) + advanced_search = request.preferences.get_value('advanced_search') # Server-Timing header request.timings = result_container.get_timings() From 4979b4f9d98186d0a5a8d10c096673c596462eb5 Mon Sep 17 00:00:00 2001 From: renyhp Date: Thu, 26 Nov 2020 15:34:53 +0100 Subject: [PATCH 3/5] Another patch --- searx/webapp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index b1fa84ced..9ec5fc33f 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -577,6 +577,7 @@ def search(): if output_format == 'html': return render( 'index.html', + advanced_search=request.preferences.get_value('advanced_search') selected_categories=get_selected_categories(request.preferences, request.form), ) else: @@ -611,7 +612,10 @@ def search(): return redirect(result_container.redirect_url) # UI - advanced_search = request.preferences.get_value('advanced_search') + # 'q' in request.from, possible value from request.form.get('advanced_search'): + # * 'on': the checkbox is checked + # * None: the checkbox is unchecked or request is sent from opensearch.xml + advanced_search = request.form.get('advanced_search') # Server-Timing header request.timings = result_container.get_timings() From 844ae0b31084bea7559cb469edc0e425983886ba Mon Sep 17 00:00:00 2001 From: renyhp Date: Thu, 26 Nov 2020 16:27:46 +0100 Subject: [PATCH 4/5] Fix syntax error --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/webapp.py b/searx/webapp.py index 9ec5fc33f..5eb6110e6 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -577,7 +577,7 @@ def search(): if output_format == 'html': return render( 'index.html', - advanced_search=request.preferences.get_value('advanced_search') + advanced_search=request.preferences.get_value('advanced_search'), selected_categories=get_selected_categories(request.preferences, request.form), ) else: From 0323606691788ed1fc59c1a825586633f0643e3b Mon Sep 17 00:00:00 2001 From: renyhp Date: Thu, 26 Nov 2020 17:26:19 +0100 Subject: [PATCH 5/5] Remove unused lines --- searx/webapp.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/searx/webapp.py b/searx/webapp.py index 5eb6110e6..c43074fd9 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -611,12 +611,6 @@ def search(): if result_container.redirect_url: return redirect(result_container.redirect_url) - # UI - # 'q' in request.from, possible value from request.form.get('advanced_search'): - # * 'on': the checkbox is checked - # * None: the checkbox is unchecked or request is sent from opensearch.xml - advanced_search = request.form.get('advanced_search') - # Server-Timing header request.timings = result_container.get_timings() @@ -725,7 +719,6 @@ def search(): pageno=search_query.pageno, time_range=search_query.time_range, number_of_results=format_decimal(number_of_results), - advanced_search=advanced_search, suggestions=suggestion_urls, answers=result_container.answers, corrections=correction_urls,