]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/controllers/gasthaus.py
When updating the inns, multiple errors in a Gasthausbox are now separated by ';'.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / gasthaus.py
1 #!/usr/bin/python2.6
2 # -*- coding: iso-8859-15 -*-
3 import logging
4
5 from pylons import request, response, session, url, tmpl_context as c
6 from pylons.controllers.util import abort, redirect
7 import webhelpers.paginate as paginate
8
9 from wradmin.lib.base import BaseController, render
10 import wradmin.model as model
11 import sqlalchemy as sa
12 import formencode
13 import re
14
15 import wrpylib.wrmwmarkup
16 import wrpylib.wrmwcache
17 import wrpylib.mwapi
18
19 log = logging.getLogger(__name__)
20
21 class GasthausController(BaseController):
22
23     def list(self):
24         "Lists all inns"
25         q = model.meta.Session.query(model.WrInnCache)
26         q = q.order_by(model.WrInnCache.page_title)
27         c.paginator = paginate.Page(q, page=int(request.params.get('page', 1)), items_per_page = 25)
28         return render('gasthaus_list.html')
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'] = u'Die Gasthausliste wurde erfolgreich aktualisiert.'
46         except wrpylib.wrmwcache.UpdateCacheError as e:
47             title = unicode(e.args[1])
48             title = wrpylib.mwapi.to_title(title)
49             msg = unicode(e.args[2])
50             msg = msg.replace('\n', '; ')
51             if len(e.args) == 3: session['flash'] = u"Fehler bei Gasthaus '{0}': {1}".format(title, msg)
52             else: session['flash'] = unicode(e)
53         session.save()
54         # Redirect to result page
55         return redirect(url(controller='gasthaus', action='list'))
56