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