]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Make the sqlalchemy database engine global.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 20 Oct 2017 22:09:42 +0000 (22:09 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 20 Oct 2017 22:09:42 +0000 (22:09 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wradmin/trunk@2709 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/__init__.py

index bbbbd92a3d1b4bba52d5a97242efcd6f7aa5e309..560ac83e13b76b16ef8e319e8f66d2a4821c9787 100644 (file)
@@ -13,22 +13,20 @@ from wradmin.controllers.coordtool import CoordtoolController
 
 app = Flask(__name__)
 app.config.from_envvar('WRADMIN_SETTINGS')
+db_engine = create_engine(app.config['DATABASE_URI'])
+wradmin.model.init_model(db_engine)
 
 
 def get_db():
-    """Opens a new database connection if there is none yet for the
-    current application context.
-    """
+    """Opens a new database connection if there is none yet for the current application context."""
     if not hasattr(g, 'db'):
-        g.db_engine = create_engine(app.config['DATABASE_URI'])
-        wradmin.model.init_model(g.db_engine)
-        g.db = g.db_engine.connect()
+        g.db = db_engine.connect()
     return g.db
 
 
 @app.teardown_appcontext
 def close_db(error):
-    """Closes the database again at the end of the request."""
+    """Closes the database connection at the end of the request."""
     if hasattr(g, 'db'):
         g.db.close()