Last active
January 4, 2022 01:39
-
-
Save hest/8a848b3a4d50de2c494264100d60b94a to your computer and use it in GitHub Desktop.
SQLAlchemy-Utils ArrowType with Flask-Babel Timezone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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