Upgrade to Flask-SqlAlchemy 2.0 (dev) and add custom SignallingSession

Necessary for tests to work
master
Steven Loria 11 years ago
parent de741805c5
commit eeb9476226
  1. 4
      {{cookiecutter.app_name}}/requirements/prod.txt
  2. 35
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/extensions.py

@ -8,8 +8,8 @@ Jinja2==2.7
itsdangerous==0.23 itsdangerous==0.23
# Database # Database
Flask-SQLAlchemy==1.0 -e git://github.com/mitsuhiko/flask-sqlalchemy.git#egg=flask-sqlalchemy
SQLAlchemy==0.8.3 SQLAlchemy==0.9.4
# Migrations # Migrations
Flask-Migrate>=1.0.0 Flask-Migrate>=1.0.0

@ -9,8 +9,39 @@ bcrypt = Bcrypt()
from flask.ext.login import LoginManager from flask.ext.login import LoginManager
login_manager = LoginManager() login_manager = LoginManager()
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.sqlalchemy import SQLAlchemy, SignallingSession, SessionBase
db = SQLAlchemy() class _SignallingSession(SignallingSession):
"""A subclass of `SignallingSession` that allows for `binds` to be specified
in the `options` keyword arguments.
"""
def __init__(self, db, autocommit=False, autoflush=True, **options):
self.app = db.get_app()
self._model_changes = {}
self.emit_modification_signals = \
self.app.config['SQLALCHEMY_TRACK_MODIFICATIONS']
bind = options.pop('bind', None)
if bind is None:
bind = db.engine
binds = options.pop('binds', None)
if binds is None:
binds = db.get_binds(self.app)
SessionBase.__init__(self,
autocommit=autocommit,
autoflush=autoflush,
bind=bind,
binds=binds,
**options)
class _SQLAlchemy(SQLAlchemy):
"""A subclass of `SQLAlchemy` that uses `_SignallingSession`."""
def create_session(self, options):
return _SignallingSession(self, **options)
db = _SQLAlchemy()
from flask.ext.migrate import Migrate from flask.ext.migrate import Migrate
migrate = Migrate() migrate = Migrate()

Loading…
Cancel
Save