]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Remove explicit get_db and now calling Session.remove() at the end of requests.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 23 Oct 2017 19:23:13 +0000 (19:23 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 23 Oct 2017 19:23:13 +0000 (19:23 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wradmin/trunk@2717 7aebc617-e5e2-0310-91dc-80fb5f6d2477

tests/test_wradmin.py
wradmin/__init__.py

index 15256d979bbb36990a8e270182bd01367bef7161..7264e8489157d19d9ca03f1562d848dc4b9eae41 100644 (file)
@@ -36,7 +36,7 @@ class TestDbWradmin(WradminTestBase):
             # fill database
             with open('tests/testdb.sql', 'r') as f:
                 sql = f.read()
-            with wradmin.get_db() as con:
+            with wradmin.model.meta.engine.begin() as con:
                 con.execute(sql)
 
                 # update dates
index 560ac83e13b76b16ef8e319e8f66d2a4821c9787..0c450c64eb539834c1db78057605403049292186 100644 (file)
@@ -13,22 +13,13 @@ 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."""
-    if not hasattr(g, 'db'):
-        g.db = db_engine.connect()
-    return g.db
+wradmin.model.init_model(create_engine(app.config['DATABASE_URI']))
 
 
 @app.teardown_appcontext
-def close_db(error):
-    """Closes the database connection at the end of the request."""
-    if hasattr(g, 'db'):
-        g.db.close()
+def remove_db_session(error):
+    """Removes the database session at the end of the request."""
+    wradmin.model.meta.Session.remove()
 
 
 @app.route("/")
@@ -38,61 +29,51 @@ def index():
 
 @app.route("/rodelbahn/list")
 def rodelbahn_list():
-    get_db()
     return RodelbahnController().list()
 
 
 @app.route("/rodelbahn/view/<int:id>")
 def rodelbahn_view(id):
-    get_db()
     return RodelbahnController().view(id)
 
 
 @app.route("/rodelbahn/update")
 def rodelbahn_update():
-    get_db()
     return RodelbahnController().update()
 
 
 @app.route("/rodelbahn/update_regioncache")
 def rodelbahn_update_regioncache():
-    get_db()
     return RodelbahnController().update_regioncache()
 
 
 @app.route("/bericht/list")
 def bericht_list():
-    get_db()
     return BerichtController().list()
 
 
 @app.route("/bericht/view/<int:id>")
 def bericht_view(id):
-    get_db()
     return BerichtController().view(id)
 
 
 @app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
 def bericht_change_date_invalid(id):
-    get_db()
     return BerichtController().change_date_invalid(id)
 
 
 @app.route("/gasthaus/list")
 def gasthaus_list():
-    get_db()
     return GasthausController().list()
 
 
 @app.route("/gasthaus/view/<int:id>")
 def gasthaus_view(id):
-    get_db()
     return GasthausController().view(id)
 
 
 @app.route("/gasthaus/update")
 def gasthaus_update():
-    get_db()
     return GasthausController().update()