]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/__init__.py
560ac83e13b76b16ef8e319e8f66d2a4821c9787
[philipp/winterrodeln/wradmin.git] / wradmin / __init__.py
1 # http://flask.pocoo.org/
2 # FLASK_APP=wradmin FLASK_DEBUG=1 WRADMIN_SETTINGS=development.cfg python3 -m flask run
3 # FLASK_APP=wradmin WRADMIN_SETTINGS=production.cfg python3 -m flask run
4 from flask import Flask, send_from_directory, abort, g
5 from sqlalchemy.engine import create_engine
6 import wradmin.model
7 from wradmin.genshi import render_genshi_template
8 from wradmin.controllers.rodelbahn import RodelbahnController
9 from wradmin.controllers.gasthaus import GasthausController
10 from wradmin.controllers.bericht import BerichtController
11 from wradmin.controllers.coordtool import CoordtoolController
12
13
14 app = Flask(__name__)
15 app.config.from_envvar('WRADMIN_SETTINGS')
16 db_engine = create_engine(app.config['DATABASE_URI'])
17 wradmin.model.init_model(db_engine)
18
19
20 def get_db():
21     """Opens a new database connection if there is none yet for the current application context."""
22     if not hasattr(g, 'db'):
23         g.db = db_engine.connect()
24     return g.db
25
26
27 @app.teardown_appcontext
28 def close_db(error):
29     """Closes the database connection at the end of the request."""
30     if hasattr(g, 'db'):
31         g.db.close()
32
33
34 @app.route("/")
35 def index():
36     return render_genshi_template('index.html')
37
38
39 @app.route("/rodelbahn/list")
40 def rodelbahn_list():
41     get_db()
42     return RodelbahnController().list()
43
44
45 @app.route("/rodelbahn/view/<int:id>")
46 def rodelbahn_view(id):
47     get_db()
48     return RodelbahnController().view(id)
49
50
51 @app.route("/rodelbahn/update")
52 def rodelbahn_update():
53     get_db()
54     return RodelbahnController().update()
55
56
57 @app.route("/rodelbahn/update_regioncache")
58 def rodelbahn_update_regioncache():
59     get_db()
60     return RodelbahnController().update_regioncache()
61
62
63 @app.route("/bericht/list")
64 def bericht_list():
65     get_db()
66     return BerichtController().list()
67
68
69 @app.route("/bericht/view/<int:id>")
70 def bericht_view(id):
71     get_db()
72     return BerichtController().view(id)
73
74
75 @app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
76 def bericht_change_date_invalid(id):
77     get_db()
78     return BerichtController().change_date_invalid(id)
79
80
81 @app.route("/gasthaus/list")
82 def gasthaus_list():
83     get_db()
84     return GasthausController().list()
85
86
87 @app.route("/gasthaus/view/<int:id>")
88 def gasthaus_view(id):
89     get_db()
90     return GasthausController().view(id)
91
92
93 @app.route("/gasthaus/update")
94 def gasthaus_update():
95     get_db()
96     return GasthausController().update()
97
98
99 @app.route("/coordtool/index")
100 def coordtool_index():
101     return CoordtoolController().index()
102
103
104 @app.route("/coordtool/convert", methods=['POST'])
105 def coordtool_convert():
106     return CoordtoolController().convert()