]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/__init__.py
bericht_list 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     pass
54
55
56 @app.route("/rodelbahn/update_regioncache")
57 def rodelbahn_update_regioncache():
58     pass
59
60
61 @app.route("/bericht/list")
62 def bericht_list():
63     get_db()
64     return BerichtController().list()
65
66
67 @app.route("/bericht/view/<int:id>")
68 def bericht_view(id):
69     get_db()
70     return BerichtController().view(id)
71
72
73 @app.route("/gasthaus/list")
74 def gasthaus_list():
75     get_db()
76     return GasthausController().list()
77
78
79 @app.route("/gasthaus/view/<int:id>")
80 def gasthaus_view():
81     get_db()
82     return GasthausController().view(id)
83
84
85 @app.route("/gasthaus/update")
86 def gasthaus_update():
87     get_db()
88     return GasthausController().update()
89
90
91 @app.route("/coordtool/index")
92 def coordtool_index():
93     pass