]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/__init__.py
Fix: Wrong function was called at rodelbahn_update_regioncache.
[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/view/<int:id>")
47 def rodelbahn_view(id):
48     get_db()
49     return RodelbahnController().view(id)
50
51
52 @app.route("/rodelbahn/update")
53 def rodelbahn_update():
54     get_db()
55     return RodelbahnController().update()
56
57
58 @app.route("/rodelbahn/update_regioncache")
59 def rodelbahn_update_regioncache():
60     get_db()
61     return RodelbahnController().update_regioncache()
62
63
64 @app.route("/bericht/list")
65 def bericht_list():
66     get_db()
67     return BerichtController().list()
68
69
70 @app.route("/bericht/view/<int:id>")
71 def bericht_view(id):
72     get_db()
73     return BerichtController().view(id)
74
75
76 @app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
77 def bericht_change_date_invalid(id):
78     get_db()
79     return BerichtController().view(id)
80
81
82 @app.route("/gasthaus/list")
83 def gasthaus_list():
84     get_db()
85     return GasthausController().list()
86
87
88 @app.route("/gasthaus/view/<int:id>")
89 def gasthaus_view(id):
90     get_db()
91     return GasthausController().view(id)
92
93
94 @app.route("/gasthaus/update")
95 def gasthaus_update():
96     get_db()
97     return GasthausController().update()
98
99
100 @app.route("/coordtool/index")
101 def coordtool_index():
102     pass