]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/controllers/gasthaus.py
gasthaus_list is rendered now.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / gasthaus.py
1 #!/usr/bin/python3.4
2 #from pylons import request, response, session, url, tmpl_context as c
3 #from pylons.controllers.util import abort, redirect
4 from flask import request
5 import paginate
6 import sqlalchemy as sa
7
8 import wrpylib.wrmwmarkup
9 import wrpylib.wrmwcache
10 import wrpylib.mwmarkup
11
12 import wradmin.model as model
13 from wradmin.genshi import render_genshi_template
14
15
16 class TemplateContext:
17     pass
18
19
20 class GasthausController:
21
22     def list(self):
23         """Lists all inns"""
24         q = model.meta.Session.query(model.WrInnCache)
25         q = q.order_by(model.WrInnCache.page_title)
26         c = TemplateContext()
27         c.paginator = paginate.Page(q.all(), page=int(request.args.get('page', 1)), items_per_page = 25)
28         return render_genshi_template('gasthaus_list.html', c=c)
29     
30     
31     def view(self, id):
32         "Displays an inn"
33         q = model.meta.Session.query(model.WrInnCache)
34         c.inn =  q.get(id)
35         if c.inn is None: abort(404)
36         return render('gasthaus_view.html')
37     
38     
39     def update(self):
40         "Updates the wrinncache table from the wiki"
41         c = model.meta.Session.connection()
42         try:
43             wrpylib.wrmwcache.update_wrinncache(c)
44             model.meta.Session.commit()
45             session['flash'] = 'Die Gasthausliste wurde erfolgreich aktualisiert.'
46         except wrpylib.wrmwcache.UpdateCacheError as e:
47             title = str(e.args[1])
48             title = wrpylib.mwmarkup.to_title(title)
49             msg = str(e.args[2])
50             msg = msg.replace('\n', '; ')
51             if len(e.args) == 3: session['flash'] = "Fehler bei Gasthaus '{0}': {1}".format(title, msg)
52             else: session['flash'] = str(e)
53         session.save()
54         # Redirect to result page
55         return redirect(url(controller='gasthaus', action='list'))
56