1 from flask import Flask, send_from_directory, abort, g, render_template, request, redirect, url_for, flash
2 from sqlalchemy.engine import create_engine
4 import wradmin.template_helper
5 from wradmin.controllers.rodelbahn import RodelbahnController
6 from wradmin.controllers.gasthaus import GasthausController
7 from wradmin.controllers.bericht import BerichtController
8 from wradmin.controllers.coordtool import CoordtoolController
9 from wradmin.auth import password_is_correct
10 from wradmin.auth.forms import LoginForm
11 from flask_login import LoginManager, current_user, login_required, login_user, logout_user
15 app.config.from_envvar('WRADMIN_SETTINGS')
16 wradmin.model.init_model(create_engine(app.config['DATABASE_URI']))
17 app.jinja_env.globals.update(h=wradmin.template_helper.PylonsHelper())
18 login_manager = LoginManager(app)
19 login_manager.login_view = "login"
23 def _before_request():
27 @app.teardown_appcontext
28 def remove_db_session(error):
29 """Removes the database session at the end of the request."""
30 wradmin.model.meta.Session.remove()
35 return render_template('index.html')
38 @app.route("/rodelbahn/list")
40 return RodelbahnController().list()
43 @app.route("/rodelbahn/view/<int:id>")
44 def rodelbahn_view(id):
45 return RodelbahnController().view(id)
48 @app.route("/rodelbahn/update")
49 def rodelbahn_update():
50 return RodelbahnController().update()
53 @app.route("/rodelbahn/update_regioncache")
54 def rodelbahn_update_regioncache():
55 return RodelbahnController().update_regioncache()
58 @app.route("/rodelbahn/update_mapcache")
59 def rodelbahn_update_mapcache():
60 return RodelbahnController().update_mapcache()
63 @app.route("/bericht/list")
66 return BerichtController().list()
69 @app.route("/bericht/view/<int:id>")
72 return BerichtController().view(id)
75 @app.route("/bericht/change_date_invalid/<int:id>", methods=['POST'])
77 def bericht_change_date_invalid(id):
78 return BerichtController().change_date_invalid(id)
81 @app.route("/bericht/update_reportcache")
82 def bericht_update_reportcache():
83 return BerichtController().update_reportcache()
86 @app.route("/gasthaus/list")
88 return GasthausController().list()
91 @app.route("/gasthaus/view/<int:id>")
92 def gasthaus_view(id):
93 return GasthausController().view(id)
96 @app.route("/gasthaus/update")
97 def gasthaus_update():
98 return GasthausController().update()
101 @app.route("/coordtool/index")
102 def coordtool_index():
103 return CoordtoolController().index()
106 @app.route("/coordtool/convert", methods=['POST'])
107 def coordtool_convert():
108 return CoordtoolController().convert()
111 @app.route("/login", methods=['GET', 'POST'])
114 if form.validate_on_submit():
115 user = wradmin.model.meta.Session.query(wradmin.model.MwUser).filter_by(user_name=form.user_name.data).first()
116 if user is not None and password_is_correct(form.password.data, user.user_password.decode()):
117 login_user(user, form.remember_me.data)
118 next = request.args.get('next')
119 if next is None or not next.startswith('/'):
120 next = url_for('index')
121 flash('Sie sind nun angemeldet.')
122 return redirect(next)
123 flash('Ungülter Benutzername oder ungültiges Passwort.')
124 return render_template('auth/login.html', form=form)
127 @app.route("/logout")
130 flash('Sie wurden ausgeloggt.')
131 return redirect(url_for('index'))
134 @login_manager.user_loader
135 def user_loader(user_id):
136 return wradmin.model.meta.Session.query(wradmin.model.MwUser).get(user_id)