From 0bfc793194f44cc3c0e6fdeb9dc9c00c448c0324 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Fri, 12 Dec 2014 19:09:02 +0100 Subject: Add a variable with all the icons of the theme Add for the template a list of available icons in the current theme. --- searx/webapp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 541975573..bb412df69 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -291,6 +291,11 @@ def index(): for engine in result['engines']: if engine in favicons: result['favicon'] = engine + + mypath = searx_dir+"/static/"+get_current_theme_name()+"/img/" + favs=[] + for (dirpath, dirnames, filenames) in os.walk(mypath): + favs.extend(filenames) # TODO, check if timezone is calculated right if 'publishedDate' in result: @@ -344,7 +349,8 @@ def index(): suggestions=search.suggestions, answers=search.answers, infoboxes=search.infoboxes, - theme=get_current_theme_name() + theme=get_current_theme_name(), + favicons=favs ) -- cgit v1.2.3 From e71b665fd5d62ddc52fda3eca141547bb3540522 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sat, 13 Dec 2014 21:37:28 +0100 Subject: Load the list of icons only once --- searx/webapp.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index bb412df69..6387a92f4 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -71,6 +71,13 @@ babel = Babel(app) #TODO configurable via settings.yml favicons = ['wikipedia', 'youtube', 'vimeo', 'dailymotion', 'soundcloud', 'twitter', 'stackoverflow', 'github', 'deviantart'] + +global_favicons = [] +for indice,theme in enumerate(themes): + global_favicons.append([]) + theme_img_path = searx_dir+"/static/"+theme+"/img/" + for (dirpath, dirnames, filenames) in os.walk(theme_img_path): + global_favicons[indice].extend(filenames) cookie_max_age = 60 * 60 * 24 * 365 * 23 # 23 years @@ -292,11 +299,6 @@ def index(): if engine in favicons: result['favicon'] = engine - mypath = searx_dir+"/static/"+get_current_theme_name()+"/img/" - favs=[] - for (dirpath, dirnames, filenames) in os.walk(mypath): - favs.extend(filenames) - # TODO, check if timezone is calculated right if 'publishedDate' in result: result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z') @@ -350,7 +352,7 @@ def index(): answers=search.answers, infoboxes=search.infoboxes, theme=get_current_theme_name(), - favicons=favs + favicons=global_favicons[themes.index(get_current_theme_name())] ) -- cgit v1.2.3 From 83d6f366596829f2140f84c73b684bd7f783e93c Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Thu, 18 Dec 2014 16:26:32 +0100 Subject: Final commit on favicons Definitely remove engine array Change every themes to accomodate that change Tweak of video template of oscar to add link on video thumbnail --- searx/webapp.py | 8 -------- 1 file changed, 8 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 6387a92f4..ca58d8ea3 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -68,10 +68,6 @@ app.secret_key = settings['server']['secret_key'] babel = Babel(app) -#TODO configurable via settings.yml -favicons = ['wikipedia', 'youtube', 'vimeo', 'dailymotion', 'soundcloud', - 'twitter', 'stackoverflow', 'github', 'deviantart'] - global_favicons = [] for indice,theme in enumerate(themes): global_favicons.append([]) @@ -294,10 +290,6 @@ def index(): result['pretty_url'] = u'{0}[...]{1}'.format(*url_parts) else: result['pretty_url'] = result['url'] - - for engine in result['engines']: - if engine in favicons: - result['favicon'] = engine # TODO, check if timezone is calculated right if 'publishedDate' in result: -- cgit v1.2.3 From a0293d6196c708e3a79cbb2a099a46caab7e58c7 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 28 Dec 2014 15:07:11 +0100 Subject: [enh] move favicons into own directory --- searx/webapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 8d1676808..be7feee82 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -68,7 +68,7 @@ babel = Babel(app) global_favicons = [] for indice, theme in enumerate(themes): global_favicons.append([]) - theme_img_path = searx_dir+"/static/"+theme+"/img/" + theme_img_path = searx_dir+"/static/"+theme+"/img/icons/" for (dirpath, dirnames, filenames) in os.walk(theme_img_path): global_favicons[indice].extend(filenames) -- cgit v1.2.3 From 9f12605f7ebc9ca5575fc4ee9900e0e821366c4d Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Thu, 1 Jan 2015 17:48:12 +0100 Subject: [enh] themes static content refactor --- searx/webapp.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index be7feee82..2e3c2c119 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -38,7 +38,8 @@ from searx.engines import ( categories, engines, get_engines_stats, engine_shortcuts ) from searx.utils import ( - UnicodeWriter, highlight_content, html_to_text, get_themes + UnicodeWriter, highlight_content, html_to_text, get_themes, + get_static_files ) from searx.version import VERSION_STRING from searx.languages import language_codes @@ -55,6 +56,8 @@ static_path, templates_path, themes =\ default_theme = settings['server'].get('default_theme', 'default') +static_files = get_static_files(searx_dir) + app = Flask( __name__, static_folder=static_path, @@ -123,9 +126,11 @@ def get_current_theme_name(override=None): def url_for_theme(endpoint, override_theme=None, **values): - if endpoint == 'static' and values.get('filename', None): + if endpoint == 'static' and values.get('filename'): theme_name = get_current_theme_name(override=override_theme) - values['filename'] = "{}/{}".format(theme_name, values['filename']) + filename_with_theme = "themes/{}/{}".format(theme_name, values['filename']) + if filename_with_theme in static_files: + values['filename'] = filename_with_theme return url_for(endpoint, **values) -- cgit v1.2.3 From 2f9a386c0db884ffbea27f43bdcff5bfd1876ad1 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Thu, 1 Jan 2015 18:59:53 +0100 Subject: [enh] better result template handling --- searx/webapp.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 2e3c2c119..fca42d48e 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -39,7 +39,7 @@ from searx.engines import ( ) from searx.utils import ( UnicodeWriter, highlight_content, html_to_text, get_themes, - get_static_files + get_static_files, get_result_templates ) from searx.version import VERSION_STRING from searx.languages import language_codes @@ -58,6 +58,8 @@ default_theme = settings['server'].get('default_theme', 'default') static_files = get_static_files(searx_dir) +result_templates = get_result_templates(searx_dir) + app = Flask( __name__, static_folder=static_path, @@ -125,6 +127,13 @@ def get_current_theme_name(override=None): return theme_name +def get_result_template(theme, template_name): + themed_path = theme + '/result_templates/' + template_name + if themed_path in result_templates: + return themed_path + return 'result_templates/' + template_name + + def url_for_theme(endpoint, override_theme=None, **values): if endpoint == 'static' and values.get('filename'): theme_name = get_current_theme_name(override=override_theme) @@ -180,6 +189,8 @@ def render(template_name, override_theme=None, **kwargs): # override url_for function in templates kwargs['url_for'] = url_for_theme + kwargs['get_result_template'] = get_result_template + kwargs['theme'] = get_current_theme_name(override=override_theme) kwargs['template_name'] = template_name -- cgit v1.2.3 From 798bef77f9b43e713aeb9ac2938785538538a99c Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Thu, 1 Jan 2015 19:24:47 +0100 Subject: [fix] static content paths --- searx/webapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index fca42d48e..6ee9af745 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -73,7 +73,7 @@ babel = Babel(app) global_favicons = [] for indice, theme in enumerate(themes): global_favicons.append([]) - theme_img_path = searx_dir+"/static/"+theme+"/img/icons/" + theme_img_path = searx_dir+"/static/themes/"+theme+"/img/icons/" for (dirpath, dirnames, filenames) in os.walk(theme_img_path): global_favicons[indice].extend(filenames) @@ -506,7 +506,7 @@ def opensearch(): @app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, - 'static', + 'static/themes', get_current_theme_name(), 'img'), 'favicon.png', -- cgit v1.2.3 From 299a80a1eb2eecb80f5c50da261a9eab1900b572 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 9 Jan 2015 04:13:05 +0100 Subject: [enh] using the logger --- searx/webapp.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 6ee9af745..24d329858 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -47,8 +47,11 @@ from searx.https_rewrite import https_url_rewrite from searx.search import Search from searx.query import Query from searx.autocomplete import backends as autocomplete_backends +from searx import logger +logger = logger.getChild('webapp') + static_path, templates_path, themes =\ get_themes(settings['themes_path'] if settings.get('themes_path') @@ -68,6 +71,8 @@ app = Flask( app.secret_key = settings['server']['secret_key'] +app.logger.addHandler(logger) + babel = Babel(app) global_favicons = [] -- cgit v1.2.3