def state(): """ State view. :return: json with serialized information about the current user """ refresh() if current_user.is_anonymous: resp = { 'loggedIn': False, 'user': None, 'userInfo': None, 'language': get_locale().language } else: ui = session.get('user_info', None) if ui and not isinstance(ui, dict): ui = ui.to_dict() resp = { 'loggedIn': True, 'user': { 'id': current_user.id, 'email': current_user.email, 'roles': [{ 'id': x.name, 'label': x.description } for x in current_user.roles] }, 'userInfo': humps.camelize(ui) if ui else {}, 'language': get_locale().language } prepare_state_view_data.send(current_user, state=resp) return jsonify(resp)
def login_status(): refresh() if current_user.is_anonymous: resp = { 'logged_in': False, 'user': None, 'user_info': None, 'language': get_locale().language } else: resp = { 'logged_in': True, 'user': { 'id': current_user.id, 'email': current_user.email, 'roles': [{ 'id': x.name, 'label': x.description } for x in current_user.roles] }, 'user_info': session.get('user_info', None).to_dict() if session.get( 'user_info', None) else None, 'language': get_locale().language } return jsonify(resp)
def index(): refresh() # day = "Saturday" response_data = { 'day': "Saturday", } return ops_render('manage/index.html', response_data)
def get_set_lang(): refresh() current_locale = get_locale() resp = jsonify({ 'language': current_locale.language, 'variant': current_locale.variant, }) resp.set_cookie('language', current_locale.language) return resp
def test_refreshing(self): app = flask.Flask(__name__) b = babel.Babel(app) d = datetime(2010, 4, 12, 13, 46) with app.test_request_context(): assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00 PM' app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna' babel.refresh() assert babel.format_datetime(d) == 'Apr 12, 2010, 3:46:00 PM'
def test_refreshing(self): app = flask.Flask(__name__) b = babel.Babel(app) d = datetime(2010, 4, 12, 13, 46) with app.test_request_context(): assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00 PM' app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna' babel.refresh() assert babel.format_datetime(d) == 'Apr 12, 2010, 3:46:00 PM'
def language(lang_code): '''Force a given language''' ctx = None if not request: ctx = current_app.test_request_context() ctx.push() backup = g.get('lang_code') g.lang_code = lang_code refresh() yield g.lang_code = backup if ctx: ctx.pop() refresh()
def language(lang_code): '''Force a given language''' ctx = None if not request: ctx = current_app.test_request_context() ctx.push() backup = g.get('lang_code') g.lang_code = lang_code refresh() yield g.lang_code = backup if ctx: ctx.pop() refresh()
def change_lang(self): """ {{ url_for('user_menu.change_lang') }}?locale=fr """ from flask_babelex import refresh locale = request.args.get("locale", None) current_lang = session.get(constants.SESSION_LANG_KEY, None) if locale and current_lang and locale != current_lang and locale in dict(current_app.config.get('ACCEPT_LANGUAGES_CHOICES')).keys(): session[constants.SESSION_LANG_KEY] = locale refresh() _next = request.args.get("next") or request.referrer or request.url return redirect(_next)
def change_lang(self): """ {{ url_for('user_menu.change_lang') }}?locale=fr """ from flask_babelex import refresh locale = request.args.get("locale", None) current_lang = session.get(constants.SESSION_LANG_KEY, None) if locale and current_lang and locale != current_lang and locale in dict( current_app.config.get('ACCEPT_LANGUAGES_CHOICES')).keys(): flash(gettext(u"The language has been updated")) session[constants.SESSION_LANG_KEY] = locale refresh() _next = request.args.get("next") or request.referrer or request.url return redirect(_next)
def index(): from flask_babelex import refresh refresh() return redirect(url_for('security.login'))