def gvars(app):
    @app.before_request
    def gdebug():
        if app.debug:
            g.debug = True
        else:
            g.debug = False

    app.context_processor(backends)

    from .models import User

    @login_manager.user_loader
    def load_user(userid):
        try:
            return User.query.get(int(userid))
        except (TypeError, __HOLE__):
            pass

    @app.before_request
    def guser():
        g.user = login.current_user

    @app.context_processor
    def inject_user():
        try:
            return {'user': g.user}
        except AttributeError:
            return {'user': None}

    @babel.localeselector
    def get_locale():
        if g.user:
            if hasattr(g.user, 'ui_lang'):
                return g.user.ui_lang

        accept_languages = app.config.get('ACCEPT_LANGUAGES')
        return request.accept_languages.best_match(accept_languages)
dataset/ETHPy150Open xen/flask-project-template/project/app.py/gvars