]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/controllers/gasthaus.py
Remove shebang in several files.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / gasthaus.py
1 from flask import request, abort, redirect, url_for, flash, render_template
2 import paginate
3
4 import wrpylib.wrmwmarkup
5 import wrpylib.wrmwcache
6 import wrpylib.mwmarkup
7
8 import wradmin.model as model
9
10
11 class GasthausController:
12
13     def list(self):
14         """Lists all inns"""
15         q = model.meta.Session.query(model.WrInnCache)
16         q = q.order_by(model.WrInnCache.page_title)
17         paginator = paginate.Page(q.all(), page=int(request.args.get('page', 1)),
18                                   url_maker=lambda page: url_for('gasthaus_list', page=page),
19                                   items_per_page=25)
20         return render_template('gasthaus_list.html', paginator=paginator)
21
22     def view(self, id):
23         """Displays an inn"""
24         q = model.meta.Session.query(model.WrInnCache)
25         inn = q.get(id)
26         if inn is None:
27             abort(404)
28         return render_template('gasthaus_view.html', inn=inn)
29
30     def update(self):
31         """Updates the wrinncache table from the wiki"""
32         c = model.meta.Session.connection()
33         try:
34             wrpylib.wrmwcache.update_wrinncache(c)
35             model.meta.Session.commit()
36             flash('Die Gasthausliste wurde erfolgreich aktualisiert.', 'info')
37         except wrpylib.wrmwcache.UpdateCacheError as e:
38             title = str(e.args[1])
39             title = wrpylib.mwmarkup.dbkey_to_title(title)
40             msg = str(e.args[2])
41             msg = msg.replace('\n', '; ')
42             if len(e.args) == 3:
43                 flash("Fehler bei Gasthaus '{0}': {1}".format(title, msg), 'error')
44             else: flash(str(e), 'error')
45         # Redirect to result page
46         return redirect(url_for('gasthaus_list'))