From: philipp Date: Mon, 23 Oct 2017 19:23:13 +0000 (+0000) Subject: Remove explicit get_db and now calling Session.remove() at the end of requests. X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wradmin.git/commitdiff_plain/a65f2f5a88e41e122eeb13b62a97d757b4835981 Remove explicit get_db and now calling Session.remove() at the end of requests. git-svn-id: http://www.winterrodeln.org/svn/wradmin/trunk@2717 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- diff --git a/tests/test_wradmin.py b/tests/test_wradmin.py index 15256d9..7264e84 100644 --- a/tests/test_wradmin.py +++ b/tests/test_wradmin.py @@ -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 diff --git a/wradmin/__init__.py b/wradmin/__init__.py index 560ac83..0c450c6 100644 --- a/wradmin/__init__.py +++ b/wradmin/__init__.py @@ -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/") 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/") def bericht_view(id): - get_db() return BerichtController().view(id) @app.route("/bericht/change_date_invalid/", 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/") def gasthaus_view(id): - get_db() return GasthausController().view(id) @app.route("/gasthaus/update") def gasthaus_update(): - get_db() return GasthausController().update()