diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2014-11-30 15:08:40 -0600 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2014-12-03 15:40:57 -0600 |
commit | f7521cac34dc573bdf426da02b5c5b7f224c7f8e (patch) | |
tree | 1524a74d3f772ea6fbc37191067c71a480db7c15 | |
parent | 5cbdb15cdbe2254ead37917f00769b2d77bd60a8 (diff) | |
download | mediagoblin-f7521cac34dc573bdf426da02b5c5b7f224c7f8e.tar.lz mediagoblin-f7521cac34dc573bdf426da02b5c5b7f224c7f8e.tar.xz mediagoblin-f7521cac34dc573bdf426da02b5c5b7f224c7f8e.zip |
Attach the base models to sessions and the DatabaseMaster for backwards compatibility
Really we should stop relying on that though.
-rw-r--r-- | mediagoblin/db/open.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py index 81cd019c..c094f753 100644 --- a/mediagoblin/db/open.py +++ b/mediagoblin/db/open.py @@ -28,6 +28,16 @@ _log = logging.getLogger(__name__) from mediagoblin.tools.transition import DISABLE_GLOBALS +def set_models_as_attributes(obj): + """ + Set all models as attributes on this object, for convenience + + TODO: This should eventually be deprecated. + """ + for k, v in six.iteritems(Base._decl_class_registry): + setattr(obj, k, v) + + if not DISABLE_GLOBALS: from mediagoblin.db.base import Session @@ -35,8 +45,7 @@ if not DISABLE_GLOBALS: def __init__(self, engine): self.engine = engine - for k, v in six.iteritems(Base._decl_class_registry): - setattr(self, k, v) + set_models_as_attributes(self) def commit(self): Session.commit() @@ -69,6 +78,7 @@ else: def __init__(self, engine): self.engine = engine self.Session = sessionmaker(bind=engine) + set_models_as_attributes(self) @contextmanager def session_scope(self): @@ -106,6 +116,8 @@ else: session.save = save session.check_session_clean = check_session_clean session.reset_after_request = reset_after_request + + set_models_as_attributes(session) ##################################### try: |