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