From 3dc5f811def121a48c17bdb3bb419e5108675e04 Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sat, 5 Dec 2015 16:42:50 +0000 Subject: Refactor and cleanup --- mach2.py | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/mach2.py b/mach2.py index 7d4ff68..f609534 100644 --- a/mach2.py +++ b/mach2.py @@ -31,43 +31,11 @@ app.config.from_object(__name__) config = configparser.ConfigParser() config.read("mach2.ini") -app.config["DEBUG"] = config["DEFAULT"]["debug"] - login_manager = LoginManager() login_manager.login_view = "login" -login_manager.session_protection = "strong" - - -def get_db(): - db = getattr(g, "_database", None) - if db is None: - db = sqlite3.connect(DATABASE) - db.row_factory = sqlite3.Row - setattr(g, "_database", db) - - return db - - -@app.teardown_appcontext -def close_connection(exception): - db = getattr(g, "_database", None) - if db is not None: - db.close() - - -def query_db(query, args=(), one=False): - cur = get_db().execute(query, args) - rv = cur.fetchall() - cur.close() - return (rv[0] if rv else None) if one else rv - - -config = configparser.ConfigParser() -config.read("mach2.ini") -login_manager = LoginManager() -login_manager.login_view = "login" -login_manager.session_protection = "strong" +login_manager.init_app(app) +compress.init_app(app) def get_db(): @@ -408,7 +376,4 @@ def logout(): if __name__ == "__main__": - login_manager.init_app(app) - compress.init_app(app) - app.run() -- cgit v1.2.3