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