summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2015-12-05 16:42:50 +0000
committerMichaël Ball <michael.ball@gmail.com>2015-12-05 16:42:50 +0000
commit3dc5f811def121a48c17bdb3bb419e5108675e04 (patch)
treec17e69cc10c1386d6eced156c243455034d3da27
parent9715f7538e4869bc3369bfdb0f2bb83b9d04f5d0 (diff)
Refactor and cleanup
-rw-r--r--mach2.py39
1 files 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()