Refactor get_locale() to be cleaner

This commit is contained in:
rubenwardy 2022-01-25 01:35:57 +00:00
parent 7aac597216
commit 9fcbbdc472

@ -130,8 +130,10 @@ def get_locale():
return current_user.locale
locale = request.cookies.get("locale")
if locale in locales:
if current_user.is_authenticated:
if locale not in locales:
locale = request.accept_languages.best_match(locales)
if locale and current_user.is_authenticated:
new_session = models.db.create_session({})()
new_session.query(models.User) \
.filter(models.User.username == current_user.username) \
@ -141,7 +143,6 @@ def get_locale():
return locale
return request.accept_languages.best_match(locales)
@app.route("/set-locale/", methods=["POST"])