From e7de9674b14c2ff06fac009274742819d6468138 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 8 Feb 2015 21:53:37 +0100 Subject: [enh] add safesearch functionality 2 = strict 1 = moderate 0 = none --- searx/webapp.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 253e50486..7266de0f0 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -267,6 +267,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['method'] = request.cookies.get('method', 'POST') + kwargs['safesearch'] = request.cookies.get('safesearch', '1') + # override url_for function in templates kwargs['url_for'] = url_for_theme @@ -455,6 +457,10 @@ def preferences(): Settings that are going to be saved as cookies.""" lang = None image_proxy = request.cookies.get('image_proxy', settings['server'].get('image_proxy')) + try: + savesearch = int(request.cookies.get('savesearch', 1)) + except ValueError: + savesearch = 1 if request.cookies.get('language')\ and request.cookies['language'] in (x[0] for x in language_codes): @@ -471,6 +477,8 @@ def preferences(): locale = None autocomplete = '' method = 'POST' + safesearch = '1' + for pd_name, pd in request.form.items(): if pd_name.startswith('category_'): category = pd_name[9:] @@ -489,6 +497,8 @@ def preferences(): lang = pd elif pd_name == 'method': method = pd + elif pd_name == 'safesearch': + safesearch = pd elif pd_name.startswith('engine_'): if pd_name.find('__') > -1: engine_name, category = pd_name.replace('engine_', '', 1).split('__', 1) @@ -529,6 +539,8 @@ def preferences(): ) resp.set_cookie('method', method, max_age=cookie_max_age) + + resp.set_cookie('safesearch', safesearch, max_age=cookie_max_age) resp.set_cookie('image_proxy', image_proxy, max_age=cookie_max_age) -- cgit v1.2.3 From 832ea60e3d19add2ffa857bc420ff33af83aac5c Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 8 Feb 2015 22:01:24 +0100 Subject: [fix] pep8, tests --- searx/webapp.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 7266de0f0..861f3aa29 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -457,10 +457,6 @@ def preferences(): Settings that are going to be saved as cookies.""" lang = None image_proxy = request.cookies.get('image_proxy', settings['server'].get('image_proxy')) - try: - savesearch = int(request.cookies.get('savesearch', 1)) - except ValueError: - savesearch = 1 if request.cookies.get('language')\ and request.cookies['language'] in (x[0] for x in language_codes): @@ -539,7 +535,7 @@ def preferences(): ) resp.set_cookie('method', method, max_age=cookie_max_age) - + resp.set_cookie('safesearch', safesearch, max_age=cookie_max_age) resp.set_cookie('image_proxy', image_proxy, max_age=cookie_max_age) -- cgit v1.2.3