]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/__init__.py
780492872d8c54aa44ac2a640982b6da32a1328d
[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
17
18 def get_db():
19     """Opens a new database connection if there is none yet for the
20     current application context.
21     """
22     if not hasattr(g, 'db'):
23         g.db_engine = create_engine(app.config['DATABASE_URI'])
24         wradmin.model.init_model(g.db_engine)
25         g.db = g.db_engine.connect()
26     return g.db
27
28
29 @app.teardown_appcontext
30 def close_db(error):
31     """Closes the database again at the end of the request."""
32     if hasattr(g, 'db'):
33         g.db.close()
34
35
36 @app.route("/")
37 def index():
38     return render_genshi_template('index.html')
39
40
41 @app.route("/rodelbahn/list")
42 def rodelbahn_list():
43     get_db()
44     return RodelbahnController().list()
45
46
47 @app.route("/rodelbahn/view/<int:id>")
48 def rodelbahn_view(id):
49     get_db()
50     return RodelbahnController().view(id)
51
52
53 @app.route("/rodelbahn/update")
54 def rodelbahn_update():
55     get_db()
56     return RodelbahnController().update()
57
58
59 @app.route("/rodelbahn/update_regioncache")
60 def rodelbahn_update_regioncache():
61     get_db()
62     return RodelbahnController().update_regioncache()
63
64
65 @app.route("/bericht/list")
66 def bericht_list():
67     get_db()
68     return BerichtController().list()
69
70
71 @app.route("/bericht/view/<int:id>")
72 def bericht_view(id):
73     get_db()
74     return BerichtController().view(id)
75
76
77 @app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
78 def bericht_change_date_invalid(id):
79     get_db()
80     return BerichtController().view(id)
81
82
83 @app.route("/gasthaus/list")
84 def gasthaus_list():
85     get_db()
86     return GasthausController().list()
87
88
89 @app.route("/gasthaus/view/<int:id>")
90 def gasthaus_view(id):
91     get_db()
92     return GasthausController().view(id)
93
94
95 @app.route("/gasthaus/update")
96 def gasthaus_update():
97     get_db()
98     return GasthausController().update()
99
100
101 @app.route("/coordtool/index")
102 def coordtool_index():
103     return CoordtoolController().index()
104
105
106 @app.route("/coordtool/convert", methods=['POST'])
107 def coordtool_convert():
108     return CoordtoolController().convert()