]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/__init__.py
Rename wradmin.genshi to wradmin.template_helper.
[philipp/winterrodeln/wradmin.git] / wradmin / __init__.py
index 0a2ef028cb688d210b935623dc2b5284eee33a3f..85e456e4b0c0bd71db76cca811b9acd1b3333dd1 100644 (file)
@@ -1,93 +1,88 @@
 # http://flask.pocoo.org/
 # FLASK_APP=wradmin FLASK_DEBUG=1 WRADMIN_SETTINGS=development.cfg python3 -m flask run
 # FLASK_APP=wradmin WRADMIN_SETTINGS=production.cfg python3 -m flask run
-from flask import Flask, send_from_directory, abort, g
+from flask import Flask, send_from_directory, abort, g, render_template
 from sqlalchemy.engine import create_engine
 import wradmin.model
-from wradmin.genshi import render_genshi_template
+import wradmin.template_helper
 from wradmin.controllers.rodelbahn import RodelbahnController
 from wradmin.controllers.gasthaus import GasthausController
 from wradmin.controllers.bericht import BerichtController
+from wradmin.controllers.coordtool import CoordtoolController
 
 
 app = Flask(__name__)
 app.config.from_envvar('WRADMIN_SETTINGS')
-
-
-def get_db():
-    """Opens a new database connection if there is none yet for the
-    current application context.
-    """
-    if not hasattr(g, 'db'):
-        g.db_engine = create_engine(app.config['DATABASE_URI'])
-        wradmin.model.init_model(g.db_engine)
-        g.db = g.db_engine.connect()
-    return g.db
+wradmin.model.init_model(create_engine(app.config['DATABASE_URI']))
+app.jinja_env.globals.update(h=wradmin.template_helper.PylonsHelper())
 
 
 @app.teardown_appcontext
-def close_db(error):
-    """Closes the database again at the end of the request."""
-    if hasattr(g, 'db'):
-        g.db.close()
+def remove_db_session(error):
+    """Removes the database session at the end of the request."""
+    wradmin.model.meta.Session.remove()
 
 
 @app.route("/")
 def index():
-    return render_genshi_template('index.html')
+    return render_template('index.html')
 
 
 @app.route("/rodelbahn/list")
 def rodelbahn_list():
-    get_db()
     return RodelbahnController().list()
 
 
-@app.route("/rodelbahn/update")
-def rodelbahn_update():
-    pass
-
-
 @app.route("/rodelbahn/view/<int:id>")
 def rodelbahn_view(id):
-    pass
+    return RodelbahnController().view(id)
+
+
+@app.route("/rodelbahn/update")
+def rodelbahn_update():
+    return RodelbahnController().update()
 
 
 @app.route("/rodelbahn/update_regioncache")
 def rodelbahn_update_regioncache():
-    pass
+    return RodelbahnController().update_regioncache()
 
 
 @app.route("/bericht/list")
 def bericht_list():
-    get_db()
     return BerichtController().list()
 
 
 @app.route("/bericht/view/<int:id>")
 def bericht_view(id):
-    get_db()
     return BerichtController().view(id)
 
 
+@app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
+def bericht_change_date_invalid(id):
+    return BerichtController().change_date_invalid(id)
+
+
 @app.route("/gasthaus/list")
 def gasthaus_list():
-    get_db()
     return GasthausController().list()
 
 
 @app.route("/gasthaus/view/<int:id>")
-def gasthaus_view():
-    get_db()
+def gasthaus_view(id):
     return GasthausController().view(id)
 
 
 @app.route("/gasthaus/update")
 def gasthaus_update():
-    get_db()
     return GasthausController().update()
 
 
 @app.route("/coordtool/index")
 def coordtool_index():
-    pass
+    return CoordtoolController().index()
+
+
+@app.route("/coordtool/convert", methods=['POST'])
+def coordtool_convert():
+    return CoordtoolController().convert()