Created
May 5, 2015 03:44
-
-
Save jean/2ca9645aeb8c956306b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# setup the db | |
from master import app | |
from flask.ext.sqlalchemy import SQLAlchemy | |
db = SQLAlchemy(app) | |
# XXX HACK | |
# | |
# Sqlite's DATETIME type doesn't support timezones, but in production | |
# we use postgres which does. So when we're using sqlite and pulling | |
# a datetime from the database, we force the value to take on the | |
# local timezone. | |
from sqlalchemy.dialects.sqlite.base import DATETIME | |
from dateutil.tz import tzlocal | |
old_processor = DATETIME.result_processor | |
def new_processor(self, *args, **kwargs): | |
def processor(value): | |
dt = old_processor(self, *args, **kwargs)(value) | |
if dt and dt.tzinfo is None: | |
dt = dt.replace(tzinfo=tzlocal()) | |
return dt | |
return processor | |
DATETIME.result_processor = new_processor |
Author
jean
commented
May 5, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment