forked from mianos/dtables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·74 lines (55 loc) · 1.86 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import sys
import configobj
import jinja_local.jinja_filters
import menu
import reports
from flask import Blueprint, Flask, flash, g, redirect, url_for
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
# some stubs because flask_login is not used. Delete these and add flask login
auth = Blueprint("auth", __name__)
@auth.route("/login")
def login():
flash("login ROFL")
return redirect(url_for("reports.users_list"))
@auth.route("/logout")
def logout():
flash("logout ROFL")
return redirect(url_for("reports.users_list"))
def create_app():
app = Flask(__name__)
# app.config['STATIC_RESOURCES'] = True
app.secret_key = "\xca\xcf\x16O\x04\x47\x0eFN\xf9\x0c,\xfb4{''<\x9b\xfc\x08\x87\xe9\x13"
app.settings = configobj.ConfigObj("settings.ini")
engine = create_engine(app.settings["database"]["connection"], echo=True, pool_recycle=3600)
Session = sessionmaker(bind=engine) # autocommit=True)
menu.init_app(app)
jinja_local.jinja_filters.init_app(app)
app.register_blueprint(reports.reports, url_prefix="/reports")
app.register_blueprint(auth)
@app.route("/")
def root():
return redirect(url_for("reports.users_list"))
@app.after_request
def session_commit(response):
session = getattr(g, "session", None)
if session is not None:
g.session.commit()
return response
@app.before_request
def before_request():
g.session = Session()
@app.teardown_request
def teardown_request(exception):
session = getattr(g, "session", None)
if session is not None:
session.close()
return app
app = create_app()
if __name__ == "__main__":
if sys.platform == "darwin":
host = "localhost"
else:
host = "0.0.0.0"
app.run(debug=True, port=8080, host=host)