Remove unnecessary custom signalling session

master
Steven Loria 11 years ago
parent 56abfbe31a
commit 38adf64997
  1. 35
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/extensions.py

@ -9,39 +9,8 @@ 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, SignallingSession, SessionBase from flask.ext.sqlalchemy import SQLAlchemy
class _SignallingSession(SignallingSession): db = SQLAlchemy()
"""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