Skip to content

Instantly share code, notes, and snippets.

@hest
Last active January 4, 2022 01:39
Show Gist options
  • Save hest/8a848b3a4d50de2c494264100d60b94a to your computer and use it in GitHub Desktop.
Save hest/8a848b3a4d50de2c494264100d60b94a to your computer and use it in GitHub Desktop.
SQLAlchemy-Utils ArrowType with Flask-Babel Timezone
from flask import Flask, g
from flask_babel import Babel
"""
Use At Your Own Risk
"""
app = Flask(__name__)
# app.config.from_object(config)
babel = Babel(app)
@babel.timezoneselector
def get_timezone():
value = g.get('timezone') if g else '' # g, session, cookie
return value or config.BABEL_DEFAULT_TIMEZONE
class TimezoneArrowType(ArrowType):
def process_result_value(self, value, dialect):
if value:
return arrow.get(value).to(str(get_timezone()))
return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment