def stats(): """Render engine statistics page.""" stats = get_engines_stats() return render( 'stats.html', stats=stats, )
def stats(): """Render engine statistics page.""" stats = get_engines_stats(request.preferences) return render( 'stats.html', stats=stats, )
def stats(): """Render engine statistics page.""" global categories stats = get_engines_stats() return render( 'stats.html', stats=stats, )
def preferences(): """Render preferences page && save user preferences""" # save preferences if request.method == 'POST': resp = make_response(redirect(urljoin(settings['server']['base_url'], url_for('index')))) try: request.preferences.parse_form(request.form) except ValidationException: request.errors.append(gettext('Invalid settings, please edit your preferences')) return resp return request.preferences.save(resp) # render preferences image_proxy = request.preferences.get_value('image_proxy') lang = request.preferences.get_value('language') disabled_engines = request.preferences.engines.get_disabled() allowed_plugins = request.preferences.plugins.get_enabled() # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = {'time': None, 'warn_timeout': False, 'warn_time': False} if e.timeout > settings['outgoing']['request_timeout']: stats[e.name]['warn_timeout'] = True stats[e.name]['supports_selected_language'] = _is_selected_language_supported(e, request.preferences) # get first element [0], the engine time, # and then the second element [1] : the time (the first one is the label) for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) if engine_stat.get('avg') > settings['outgoing']['request_timeout']: stats[engine_stat.get('name')]['warn_time'] = True # end of stats return render('preferences.html', locales=settings['locales'], current_locale=get_locale(), image_proxy=image_proxy, engines_by_category=categories, stats=stats, answerers=[{'info': a.self_info(), 'keywords': a.keywords} for a in answerers], disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, doi_resolvers=settings['doi_resolvers'], current_doi_resolver=get_doi_resolver(request.args, request.preferences.get_value('doi_resolver')), allowed_plugins=allowed_plugins, theme=get_current_theme_name(), preferences_url_params=request.preferences.get_as_url_params(), base_url=get_base_url(), preferences=True)
def stats(): """Render engine statistics page.""" if not settings['general'].get('enable_stats'): return page_not_found(None) stats = get_engines_stats(request.preferences) return render( 'stats.html', stats=stats, )
def preferences(): """Render preferences page && save user preferences""" # save preferences if request.method == 'POST': resp = make_response( redirect(urljoin(settings['server']['base_url'], url_for('index')))) try: request.preferences.parse_form(request.form) except ValidationException: # TODO use flash feature of flask return resp return request.preferences.save(resp) # render preferences image_proxy = request.preferences.get_value('image_proxy') lang = request.preferences.get_value('language') disabled_engines = request.preferences.engines.get_disabled() allowed_plugins = request.preferences.plugins.get_enabled() # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = { 'time': None, 'warn_timeout': False, 'warn_time': False } if e.timeout > settings['outgoing']['request_timeout']: stats[e.name]['warn_timeout'] = True for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) if engine_stat.get('avg') > settings['outgoing']['request_timeout']: stats[engine_stat.get('name')]['warn_time'] = True # end of stats return render('preferences.html', locales=settings['locales'], current_locale=get_locale(), current_language=lang, image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, stats=stats, disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, allowed_plugins=allowed_plugins, theme=get_current_theme_name())
def preferences(): """Render preferences page && save user preferences""" # save preferences if request.method == "POST": resp = make_response(redirect(urljoin(settings["server"]["base_url"], url_for("index")))) try: request.preferences.parse_form(request.form) except ValidationException: request.errors.append(gettext("Invalid settings, please edit your preferences")) return resp return request.preferences.save(resp) # render preferences image_proxy = request.preferences.get_value("image_proxy") lang = request.preferences.get_value("language") disabled_engines = request.preferences.engines.get_disabled() allowed_plugins = request.preferences.plugins.get_enabled() # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = {"time": None, "warn_timeout": False, "warn_time": False} if e.timeout > settings["outgoing"]["request_timeout"]: stats[e.name]["warn_timeout"] = True # get first element [0], the engine time, # and then the second element [1] : the time (the first one is the label) for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get("name")]["time"] = round(engine_stat.get("avg"), 3) if engine_stat.get("avg") > settings["outgoing"]["request_timeout"]: stats[engine_stat.get("name")]["warn_time"] = True # end of stats return render( "preferences.html", locales=settings["locales"], current_locale=get_locale(), current_language=lang, image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, stats=stats, answerers=[{"info": a.self_info(), "keywords": a.keywords} for a in answerers], disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, allowed_plugins=allowed_plugins, theme=get_current_theme_name(), )
def preferences(): """Render preferences page && save user preferences""" # save preferences if request.method == 'POST': resp = make_response(redirect(urljoin(settings['server']['base_url'], url_for('index')))) try: request.preferences.parse_form(request.form) except ValidationException: # TODO use flash feature of flask return resp return request.preferences.save(resp) # render preferences image_proxy = request.preferences.get_value('image_proxy') lang = request.preferences.get_value('language') disabled_engines = request.preferences.engines.get_disabled() allowed_plugins = request.preferences.plugins.get_enabled() # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = {'time': None, 'warn_timeout': False, 'warn_time': False} if e.timeout > settings['outgoing']['request_timeout']: stats[e.name]['warn_timeout'] = True for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) if engine_stat.get('avg') > settings['outgoing']['request_timeout']: stats[engine_stat.get('name')]['warn_time'] = True # end of stats return render('preferences.html', locales=settings['locales'], current_locale=get_locale(), current_language=lang, image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, stats=stats, disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, allowed_plugins=allowed_plugins, theme=get_current_theme_name())
def stats(): global categories stats = get_engines_stats() return render('stats.html', stats=stats)
def preferences(): """Render preferences page. Settings that are going to be saved as cookies.""" lang = None image_proxy = request.cookies.get("image_proxy", settings["server"].get("image_proxy")) if request.cookies.get("language") and request.cookies["language"] in (x[0] for x in language_codes): lang = request.cookies["language"] blocked_engines = [] resp = make_response(redirect(urljoin(settings["server"]["base_url"], url_for("index")))) if request.method == "GET": blocked_engines = get_blocked_engines(engines, request.cookies) else: # on save selected_categories = [] post_disabled_plugins = [] locale = None autocomplete = "" method = "POST" safesearch = settings["search"]["safe_search"] for pd_name, pd in request.form.items(): if pd_name.startswith("category_"): category = pd_name[9:] if category not in categories: continue selected_categories.append(category) elif pd_name == "locale" and pd in settings["locales"]: locale = pd elif pd_name == "image_proxy": image_proxy = pd elif pd_name == "autocomplete": autocomplete = pd elif pd_name == "language" and (pd == "all" or pd in (x[0] for x in language_codes)): lang = pd elif pd_name == "method": method = pd elif pd_name == "safesearch": safesearch = pd elif pd_name.startswith("engine_"): if pd_name.find("__") > -1: # TODO fix underscore vs space engine_name, category = [ x.replace("_", " ") for x in pd_name.replace("engine_", "", 1).split("__", 1) ] if engine_name in engines and category in engines[engine_name].categories: blocked_engines.append((engine_name, category)) elif pd_name == "theme": theme = pd if pd in themes else default_theme elif pd_name.startswith("plugin_"): plugin_id = pd_name.replace("plugin_", "", 1) if not any(plugin.id == plugin_id for plugin in plugins): continue post_disabled_plugins.append(plugin_id) else: resp.set_cookie(pd_name, pd, max_age=cookie_max_age) disabled_plugins = [] allowed_plugins = [] for plugin in plugins: if plugin.default_on: if plugin.id in post_disabled_plugins: disabled_plugins.append(plugin.id) elif plugin.id not in post_disabled_plugins: allowed_plugins.append(plugin.id) resp.set_cookie("disabled_plugins", ",".join(disabled_plugins), max_age=cookie_max_age) resp.set_cookie("allowed_plugins", ",".join(allowed_plugins), max_age=cookie_max_age) resp.set_cookie("blocked_engines", ",".join("__".join(e) for e in blocked_engines), max_age=cookie_max_age) if locale: resp.set_cookie("locale", locale, max_age=cookie_max_age) if lang: resp.set_cookie("language", lang, max_age=cookie_max_age) if selected_categories: # cookie max age: 4 weeks resp.set_cookie("categories", ",".join(selected_categories), max_age=cookie_max_age) resp.set_cookie("autocomplete", autocomplete, max_age=cookie_max_age) resp.set_cookie("method", method, max_age=cookie_max_age) resp.set_cookie("safesearch", str(safesearch), max_age=cookie_max_age) resp.set_cookie("image_proxy", image_proxy, max_age=cookie_max_age) resp.set_cookie("theme", theme, max_age=cookie_max_age) return resp # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = {"time": None, "warn_timeout": False, "warn_time": False} if e.timeout > settings["outgoing"]["request_timeout"]: stats[e.name]["warn_timeout"] = True for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get("name")]["time"] = round(engine_stat.get("avg"), 3) if engine_stat.get("avg") > settings["outgoing"]["request_timeout"]: stats[engine_stat.get("name")]["warn_time"] = True # end of stats return render( "preferences.html", locales=settings["locales"], current_locale=get_locale(), current_language=lang or "all", image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, stats=stats, blocked_engines=blocked_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, allowed_plugins=[plugin.id for plugin in request.user_plugins], theme=get_current_theme_name(), )
def preferences(): """Render preferences page. Settings that are going to be saved as cookies.""" lang = None image_proxy = request.cookies.get('image_proxy', settings['server'].get('image_proxy')) if request.cookies.get('language')\ and request.cookies['language'] in (x[0] for x in language_codes): lang = request.cookies['language'] blocked_engines = [] resp = make_response(redirect(urljoin(settings['server']['base_url'], url_for('index')))) if request.method == 'GET': blocked_engines = get_blocked_engines(engines, request.cookies) else: # on save selected_categories = [] post_disabled_plugins = [] locale = None autocomplete = '' method = 'POST' safesearch = settings['search']['safe_search'] for pd_name, pd in request.form.items(): if pd_name.startswith('category_'): category = pd_name[9:] if category not in categories: continue selected_categories.append(category) elif pd_name == 'locale' and pd in settings['locales']: locale = pd elif pd_name == 'image_proxy': image_proxy = pd elif pd_name == 'autocomplete': autocomplete = pd elif pd_name == 'language' and (pd == 'all' or pd in (x[0] for x in language_codes)): lang = pd elif pd_name == 'method': method = pd elif pd_name == 'safesearch': safesearch = pd elif pd_name.startswith('engine_'): if pd_name.find('__') > -1: # TODO fix underscore vs space engine_name, category = [x.replace('_', ' ') for x in pd_name.replace('engine_', '', 1).split('__', 1)] if engine_name in engines and category in engines[engine_name].categories: blocked_engines.append((engine_name, category)) elif pd_name == 'theme': theme = pd if pd in themes else default_theme elif pd_name.startswith('plugin_'): plugin_id = pd_name.replace('plugin_', '', 1) if not any(plugin.id == plugin_id for plugin in plugins): continue post_disabled_plugins.append(plugin_id) else: resp.set_cookie(pd_name, pd, max_age=cookie_max_age) disabled_plugins = [] allowed_plugins = [] for plugin in plugins: if plugin.default_on: if plugin.id in post_disabled_plugins: disabled_plugins.append(plugin.id) elif plugin.id not in post_disabled_plugins: allowed_plugins.append(plugin.id) resp.set_cookie('disabled_plugins', ','.join(disabled_plugins), max_age=cookie_max_age) resp.set_cookie('allowed_plugins', ','.join(allowed_plugins), max_age=cookie_max_age) resp.set_cookie( 'blocked_engines', ','.join('__'.join(e) for e in blocked_engines), max_age=cookie_max_age ) if locale: resp.set_cookie( 'locale', locale, max_age=cookie_max_age ) if lang: resp.set_cookie( 'language', lang, max_age=cookie_max_age ) if selected_categories: # cookie max age: 4 weeks resp.set_cookie( 'categories', ','.join(selected_categories), max_age=cookie_max_age ) resp.set_cookie( 'autocomplete', autocomplete, max_age=cookie_max_age ) resp.set_cookie('method', method, max_age=cookie_max_age) resp.set_cookie('safesearch', str(safesearch), max_age=cookie_max_age) resp.set_cookie('image_proxy', image_proxy, max_age=cookie_max_age) resp.set_cookie('theme', theme, max_age=cookie_max_age) return resp # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = {'time': None, 'warn_timeout': False, 'warn_time': False} if e.timeout > settings['outgoing']['request_timeout']: stats[e.name]['warn_timeout'] = True for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) if engine_stat.get('avg') > settings['outgoing']['request_timeout']: stats[engine_stat.get('name')]['warn_time'] = True # end of stats return render('preferences.html', locales=settings['locales'], current_locale=get_locale(), current_language=lang or 'all', image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, stats=stats, blocked_engines=blocked_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, allowed_plugins=[plugin.id for plugin in request.user_plugins], theme=get_current_theme_name())
def preferences(): """Render preferences page && save user preferences""" # save preferences if request.method == "POST": resp = make_response( redirect(urljoin(settings["server"]["base_url"], url_for("index")))) try: request.preferences.parse_form(request.form) except ValidationException: request.errors.append( gettext("Invalid settings, please edit your preferences")) return resp return request.preferences.save(resp) # render preferences image_proxy = request.preferences.get_value("image_proxy") disabled_engines = request.preferences.engines.get_disabled() allowed_plugins = request.preferences.plugins.get_enabled() # stats for preferences page stats = {} engines_by_category = {} for c in categories: engines_by_category[c] = [] for e in categories[c]: if not request.preferences.validate_token(e): continue stats[e.name] = { "time": None, "warn_timeout": False, "warn_time": False } if e.timeout > settings["outgoing"]["request_timeout"]: stats[e.name]["warn_timeout"] = True stats[e.name][ "supports_selected_language"] = _is_selected_language_supported( e, request.preferences) engines_by_category[c].append(e) # get first element [0], the engine time, # and then the second element [1] : the time (the first one is the label) for engine_stat in get_engines_stats(request.preferences)[0][1]: stats[engine_stat.get("name")]["time"] = round(engine_stat.get("avg"), 3) if engine_stat.get("avg") > settings["outgoing"]["request_timeout"]: stats[engine_stat.get("name")]["warn_time"] = True # end of stats locked_preferences = list() if "preferences" in settings and "lock" in settings["preferences"]: locked_preferences = settings["preferences"]["lock"] return render( "preferences.html", selected_categories=get_selected_categories(request.preferences, request.form), all_categories=_get_ordered_categories(), locales=settings["locales"], current_locale=request.preferences.get_value("locale"), image_proxy=image_proxy, engines_by_category=engines_by_category, stats=stats, answerers=[{ "info": a.self_info(), "keywords": a.keywords } for a in answerers], disabled_engines=disabled_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, doi_resolvers=settings["doi_resolvers"], current_doi_resolver=get_doi_resolver( request.args, request.preferences.get_value("doi_resolver")), allowed_plugins=allowed_plugins, theme=get_current_theme_name(), preferences_url_params=request.preferences.get_as_url_params(), base_url=get_base_url(), locked_preferences=locked_preferences, preferences=True, )
def preferences(): """Render preferences page. Settings that are going to be saved as cookies.""" lang = None image_proxy = request.cookies.get('image_proxy', settings['server'].get('image_proxy')) if request.cookies.get('language')\ and request.cookies['language'] in (x[0] for x in language_codes): lang = request.cookies['language'] blocked_engines = [] resp = make_response( redirect(urljoin(settings['server']['base_url'], url_for('index')))) if request.method == 'GET': blocked_engines = get_blocked_engines(engines, request.cookies) else: # on save selected_categories = [] post_disabled_plugins = [] locale = None autocomplete = '' method = 'POST' safesearch = settings['search']['safe_search'] for pd_name, pd in request.form.items(): if pd_name.startswith('category_'): category = pd_name[9:] if category not in categories: continue selected_categories.append(category) elif pd_name == 'locale' and pd in settings['locales']: locale = pd elif pd_name == 'image_proxy': image_proxy = pd elif pd_name == 'autocomplete': autocomplete = pd elif pd_name == 'language' and (pd == 'all' or pd in (x[0] for x in language_codes)): lang = pd elif pd_name == 'method': method = pd elif pd_name == 'safesearch': safesearch = pd elif pd_name.startswith('engine_'): if pd_name.find('__') > -1: # TODO fix underscore vs space engine_name, category = [ x.replace('_', ' ') for x in pd_name.replace( 'engine_', '', 1).split('__', 1) ] if engine_name in engines and category in engines[ engine_name].categories: blocked_engines.append((engine_name, category)) elif pd_name == 'theme': theme = pd if pd in themes else default_theme elif pd_name.startswith('plugin_'): plugin_id = pd_name.replace('plugin_', '', 1) if not any(plugin.id == plugin_id for plugin in plugins): continue post_disabled_plugins.append(plugin_id) else: resp.set_cookie(pd_name, pd, max_age=cookie_max_age) disabled_plugins = [] allowed_plugins = [] for plugin in plugins: if plugin.default_on: if plugin.id in post_disabled_plugins: disabled_plugins.append(plugin.id) elif plugin.id not in post_disabled_plugins: allowed_plugins.append(plugin.id) resp.set_cookie('disabled_plugins', ','.join(disabled_plugins), max_age=cookie_max_age) resp.set_cookie('allowed_plugins', ','.join(allowed_plugins), max_age=cookie_max_age) resp.set_cookie('blocked_engines', ','.join('__'.join(e) for e in blocked_engines), max_age=cookie_max_age) if locale: resp.set_cookie('locale', locale, max_age=cookie_max_age) if lang: resp.set_cookie('language', lang, max_age=cookie_max_age) if selected_categories: # cookie max age: 4 weeks resp.set_cookie('categories', ','.join(selected_categories), max_age=cookie_max_age) resp.set_cookie('autocomplete', autocomplete, max_age=cookie_max_age) resp.set_cookie('method', method, max_age=cookie_max_age) resp.set_cookie('safesearch', str(safesearch), max_age=cookie_max_age) resp.set_cookie('image_proxy', image_proxy, max_age=cookie_max_age) resp.set_cookie('theme', theme, max_age=cookie_max_age) return resp # stats for preferences page stats = {} for c in categories: for e in categories[c]: stats[e.name] = { 'time': None, 'warn_timeout': False, 'warn_time': False } if e.timeout > settings['outgoing']['request_timeout']: stats[e.name]['warn_timeout'] = True for engine_stat in get_engines_stats()[0][1]: stats[engine_stat.get('name')]['time'] = round(engine_stat.get('avg'), 3) if engine_stat.get('avg') > settings['outgoing']['request_timeout']: stats[engine_stat.get('name')]['warn_time'] = True # end of stats return render( 'preferences.html', locales=settings['locales'], current_locale=get_locale(), current_language=lang or 'all', image_proxy=image_proxy, language_codes=language_codes, engines_by_category=categories, stats=stats, blocked_engines=blocked_engines, autocomplete_backends=autocomplete_backends, shortcuts={y: x for x, y in engine_shortcuts.items()}, themes=themes, plugins=plugins, allowed_plugins=[plugin.id for plugin in request.user_plugins], theme=get_current_theme_name())