]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/controllers/gasthaus.py
Use flask_sqlalchemy to manage the database connection.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / gasthaus.py
index 16dd9864824edc8da5bad245f15b54ab8281ba2e..f0d078e03d58c6ec6d1fe4183361c6395b08763d 100644 (file)
@@ -4,16 +4,16 @@ import paginate
 import wrpylib.wrmwmarkup
 import wrpylib.wrmwcache
 import wrpylib.mwmarkup
-
-import wradmin.model as model
+from wradmin.app import db
+from wradmin.model import WrInnCache
 
 
 class GasthausController:
 
     def list(self):
         """Lists all inns"""
-        q = model.meta.Session.query(model.WrInnCache)
-        q = q.order_by(model.WrInnCache.page_title)
+        q = db.session.query(WrInnCache)
+        q = q.order_by(WrInnCache.page_title)
         paginator = paginate.Page(q.all(), page=int(request.args.get('page', 1)),
                                   url_maker=lambda page: url_for('gasthaus_list', page=page),
                                   items_per_page=25)
@@ -21,7 +21,7 @@ class GasthausController:
 
     def view(self, id):
         """Displays an inn"""
-        q = model.meta.Session.query(model.WrInnCache)
+        q = db.session.query(WrInnCache)
         inn = q.get(id)
         if inn is None:
             abort(404)
@@ -29,10 +29,10 @@ class GasthausController:
 
     def update(self):
         """Updates the wrinncache table from the wiki"""
-        c = model.meta.Session.connection()
+        c = db.session.connection()
         try:
             wrpylib.wrmwcache.update_wrinncache(c)
-            model.meta.Session.commit()
+            db.session.commit()
             flash('Die Gasthausliste wurde erfolgreich aktualisiert.', 'info')
         except wrpylib.wrmwcache.UpdateCacheError as e:
             title = str(e.args[1])