Exemple #1
0
def list_engines():
    """Render engines page.

    List of all supported engines.
    """
    return render('engines.html',
                  categs=categories.items(),
                  shortcuts={y: x for x, y in engine_shortcuts.items()})
Exemple #2
0
def about():
    global categories
    return render('about.html', categs=categories.items())
Exemple #3
0
def preferences():
    """Render preferences page.

    Settings that are going to be saved as cookies."""
    lang = None

    if request.cookies.get('language')\
       and request.cookies['language'] in (x[0] for x in language_codes):
        lang = request.cookies['language']

    blocked_engines = []

    if request.method == 'GET':
        blocked_engines = request.cookies.get('blocked_engines', '').split(',')
    else:
        selected_categories = []
        locale = None
        for pd_name, pd in request.form.items():
            if pd_name.startswith('category_'):
                category = pd_name[9:]
                if not category in categories:
                    continue
                selected_categories.append(category)
            elif pd_name == 'locale' and pd in settings['locales']:
                locale = pd
            elif pd_name == 'language' and (pd == 'all' or
                                            pd in (x[0] for
                                                   x in language_codes)):
                lang = pd
            elif pd_name.startswith('engine_'):
                engine_name = pd_name.replace('engine_', '', 1)
                if engine_name in engines:
                    blocked_engines.append(engine_name)

        resp = make_response(redirect('/'))

        user_blocked_engines = request.cookies.get('blocked_engines', '').split(',')  # noqa

        if sorted(blocked_engines) != sorted(user_blocked_engines):
            # cookie max age: 4 weeks
            resp.set_cookie(
                'blocked_engines', ','.join(blocked_engines),
                max_age=60 * 60 * 24 * 7 * 4
            )

        if locale:
            # cookie max age: 4 weeks
            resp.set_cookie(
                'locale', locale,
                max_age=60 * 60 * 24 * 7 * 4
            )

        if lang:
            # cookie max age: 4 weeks
            resp.set_cookie(
                'language', lang,
                max_age=60 * 60 * 24 * 7 * 4
            )

        if selected_categories:
            # cookie max age: 4 weeks
            resp.set_cookie(
                'categories', ','.join(selected_categories),
                max_age=60 * 60 * 24 * 7 * 4
            )
        return resp
    return render('preferences.html',
                  locales=settings['locales'],
                  current_locale=get_locale(),
                  current_language=lang or 'all',
                  language_codes=language_codes,
                  categs=categories.items(),
                  blocked_engines=blocked_engines,
                  shortcuts={y: x for x, y in engine_shortcuts.items()})
Exemple #4
0
def preferences():
    """Render preferences page.

    Settings that are going to be saved as cookies."""
    lang = None

    if request.cookies.get('language')\
       and request.cookies['language'] in (x[0] for x in language_codes):
        lang = request.cookies['language']

    blocked_engines = []

    if request.method == 'GET':
        blocked_engines = request.cookies.get('blocked_engines', '').split(',')
    else:  # on save
        selected_categories = []
        locale = None
        autocomplete = ''
        method = 'POST'
        for pd_name, pd in request.form.items():
            if pd_name.startswith('category_'):
                category = pd_name[9:]
                if not category in categories:
                    continue
                selected_categories.append(category)
            elif pd_name == 'locale' and pd in settings['locales']:
                locale = 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.startswith('engine_'):
                engine_name = pd_name.replace('engine_', '', 1)
                if engine_name in engines:
                    blocked_engines.append(engine_name)
            elif pd_name == 'theme':
                theme = pd if pd in themes else default_theme

        resp = make_response(redirect(url_for('index')))

        user_blocked_engines = request.cookies.get('blocked_engines', '').split(',')  # noqa

        if sorted(blocked_engines) != sorted(user_blocked_engines):
            resp.set_cookie(
                'blocked_engines', ','.join(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(
            'theme', theme, max_age=cookie_max_age)

        return resp
    return render('preferences.html',
                  locales=settings['locales'],
                  current_locale=get_locale(),
                  current_language=lang or 'all',
                  language_codes=language_codes,
                  categs=categories.items(),
                  blocked_engines=blocked_engines,
                  autocomplete_backends=autocomplete_backends,
                  shortcuts={y: x for x, y in engine_shortcuts.items()},
                  themes=themes,
                  theme=get_current_theme_name())
Exemple #5
0
def about():
    global categories
    return render('about.html', categs=categories.items())
Exemple #6
0
def preferences():
    """Render preferences page.

    Settings that are going to be saved as cookies."""
    lang = None

    if request.cookies.get('language')\
       and request.cookies['language'] in (x[0] for x in language_codes):
        lang = request.cookies['language']

    blocked_engines = []

    if request.method == 'GET':
        blocked_engines = request.cookies.get('blocked_engines', '').split(',')
    else:
        selected_categories = []
        locale = None
        autocomplete = ''
        method = 'POST'
        for pd_name, pd in request.form.items():
            if pd_name.startswith('category_'):
                category = pd_name[9:]
                if not category in categories:
                    continue
                selected_categories.append(category)
            elif pd_name == 'locale' and pd in settings['locales']:
                locale = 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.startswith('engine_'):
                engine_name = pd_name.replace('engine_', '', 1)
                if engine_name in engines:
                    blocked_engines.append(engine_name)

        resp = make_response(redirect(url_for('index')))

        user_blocked_engines = request.cookies.get('blocked_engines',
                                                   '').split(',')  # noqa

        if sorted(blocked_engines) != sorted(user_blocked_engines):
            resp.set_cookie('blocked_engines',
                            ','.join(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)

        return resp
    return render('preferences.html',
                  locales=settings['locales'],
                  current_locale=get_locale(),
                  current_language=lang or 'all',
                  language_codes=language_codes,
                  categs=categories.items(),
                  blocked_engines=blocked_engines,
                  autocomplete_backends=autocomplete_backends,
                  shortcuts={y: x
                             for x, y in engine_shortcuts.items()})
Exemple #7
0
def list_engines():
    global categories
    return render('engines.html', categs=categories.items())
Exemple #8
0
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(url_for('index')))

    if request.method == 'GET':
        blocked_engines = get_blocked_engines(engines, request.cookies)
    else:  # on save
        selected_categories = []
        locale = None
        autocomplete = ''
        method = 'POST'
        safesearch = '1'

        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:
                    engine_name, category = 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
            else:
                resp.set_cookie(pd_name, pd, 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', 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
    return render('preferences.html',
                  locales=settings['locales'],
                  current_locale=get_locale(),
                  current_language=lang or 'all',
                  image_proxy=image_proxy,
                  language_codes=language_codes,
                  categs=categories.items(),
                  blocked_engines=blocked_engines,
                  autocomplete_backends=autocomplete_backends,
                  shortcuts={y: x for x, y in engine_shortcuts.items()},
                  themes=themes,
                  theme=get_current_theme_name())