]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Changed the rodelbahn and gasthaus controllers to use the new update function in...
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 14 Feb 2011 21:12:47 +0000 (21:12 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Mon, 14 Feb 2011 21:12:47 +0000 (21:12 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@779 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/setup.py
wradmin/wradmin/controllers/gasthaus.py
wradmin/wradmin/controllers/rodelbahn.py

index fe2cfb5f0eb5d886f6d279bac9e887911a5c1f0a..94bac3758e6742ff1174dbcb832717cb04c110df 100644 (file)
@@ -7,7 +7,7 @@ except ImportError:
 
 setup(
     name='wradmin',
-    version='1.4.4',
+    version='1.4.5',
     description='Administrative Interface for Winterrodeln',
     author='Philipp Spitzer',
     author_email='philipp.spitzer@winterrodeln.org',
index fcbea1d062cbcbb2c769a075b4a4f8a3fb4aefdf..37c1c9ceae69da9fdd955732bfd9299939b782f0 100644 (file)
@@ -13,6 +13,7 @@ import formencode
 import re
 
 import wrpylib.wrmwmarkup
+import wrpylib.wrmwcache
 
 log = logging.getLogger(__name__)
 
@@ -36,31 +37,14 @@ class GasthausController(BaseController):
     
     def update(self):
         "Updates the wrinncache table from the wiki"
-        from wradmin.model import page_table as page, wrinncache_table as wrinncache, categorylinks_table as categorylinks, revision_table as revision, text_table as text
-        from sqlalchemy.sql import select
         c = model.meta.Session.connection()
-        
-        # Query all inns
-        q = select([page, categorylinks, revision, text], (page.c.page_latest==revision.c.rev_id) & (text.c.old_id==revision.c.rev_text_id) & (categorylinks.c.cl_from==page.c.page_id) & (categorylinks.c.cl_to==u'Gasthaus'))
-        inn_pages = c.execute(q)
-        
-        # Delete all existing entries in wrinncache
-        c.execute(wrinncache.delete())
-        
-        # Refill wrinncache table
-        error_msg = u''
-        for inn_page in inn_pages:
-            try: 
-                start, end, inn = wrpylib.wrmwmarkup.gasthausbox_to_inn(inn_page.old_text, model.WrInnCache())
-                inn.page_id = inn_page.page_id
-                inn.page_title = inn_page.page_title
-                inn.under_construction = c.execute(select([categorylinks], (categorylinks.c.cl_from==inn_page.page_id) & (categorylinks.c.cl_to == u'In_Arbeit')).alias('x').count()).fetchone()[0] > 0 # It would be better to do this in the query above
-                model.meta.Session.add(inn)
-            except (RuntimeError, formencode.Invalid) as e: error_msg = u"Fehler bei Gasthaus '%s': " % inn_page.page_title + unicode(e)
-        model.meta.Session.commit()
-        
-        # Redirect to result page
-        if error_msg == '': session['flash'] = u'Die Gasthausliste wurde erfolgreich aktualisiert.'
-        else: session['flash'] = error_msg
+        try:
+            wrpylib.wrmwcache.update_wrinncache(c)
+            session['flash'] = u'Die Gasthausliste wurde erfolgreich aktualisiert.'
+        except wrpylib.wrmwcache.UpdateCacheError as e:
+            if len(e.args) == 3: session['flash'] = u"Fehler bei Gasthaus '{0}': {1}".format(e.args[1], e.args[2])
+            else: session['flash'] = unicode(e)
         session.save()
+        # Redirect to result page
         return redirect(url(controller='gasthaus', action='list'))
+
index 106751e52886f9131f00d230ba290f0745abbb50..02df026c6971a1ad08e108c53d2912a0517af6b5 100644 (file)
@@ -13,12 +13,14 @@ import formencode
 import re
 
 import wrpylib.wrmwmarkup
+import wrpylib.wrmwcache
 
 from weberror import collector        # Prevent a bug of weberror # See https://bitbucket.org/bbangert/weberror/issue/3/nameerror-global-name-fallback_encoding-is-not
 collector.FALLBACK_ENCODING = 'utf-8' # --"--
 
 log = logging.getLogger(__name__)
 
+
 class RodelbahnController(BaseController):
 
     def index(self):
@@ -46,35 +48,14 @@ class RodelbahnController(BaseController):
     
     def update(self):
         "Updates the wrsledruncache table from the wiki"
-        from wradmin.model import page_table as page, wrsledruncache_table as wrsledruncache, categorylinks_table as categorylinks, revision_table as revision, text_table as text
-        from sqlalchemy.sql import select
         c = model.meta.Session.connection()
-        
-        # As MySQL does not support transactions we make a dry run first and only continue if there is no fatal error
-        for i in range(2):
-            # Query all sledding routes
-            q = select([page, categorylinks, revision, text], (page.c.page_latest==revision.c.rev_id) & (text.c.old_id==revision.c.rev_text_id) & (categorylinks.c.cl_from==page.c.page_id) & (categorylinks.c.cl_to==u'Rodelbahn'))
-            sledding_pages = c.execute(q)
-            # Original SQL:
-            # sql = u"select page_id, rev_id, old_id, page_title, old_text, 'In_Arbeit' in (select cl_to from categorylinks where cl_from=page_id) as under_construction from page, revision, text, categorylinks where page_latest=rev_id and old_id=rev_text_id and cl_from=page_id and cl_to='Rodelbahn' order by page_title"
-            
-            # Delete all existing entries in wrsledruncache
-            if i == 1: c.execute(wrsledruncache.delete())
-            
-            # Refill wrsledruncache table
-            error_msg = u''
-            for sl in sledding_pages:
-                try: 
-                    start, end, sledrun = wrpylib.wrmwmarkup.rodelbahnbox_to_sledrun(sl.old_text, model.WrSledrunCache())
-                    sledrun.page_id = sl.page_id
-                    sledrun.page_title = sl.page_title
-                    sledrun.under_construction = c.execute(select([categorylinks], (categorylinks.c.cl_from==sl.page_id) & (categorylinks.c.cl_to == u'In_Arbeit')).alias('x').count()).fetchone()[0] > 0 # It would be better to do this in the query above
-                    if i == 1: model.meta.Session.add(sledrun)
-                except (RuntimeError, formencode.Invalid) as e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode(e)
-            if i == 1: model.meta.Session.commit()
-        
-        # Redirect to result page
-        if error_msg == '': session['flash'] = u'Die Rodelbahnliste wurde erfolgreich aktualisiert.'
-        else: session['flash'] = error_msg
+        try:
+            wrpylib.wrmwcache.update_wrsledruncache(c)
+            session['flash'] = u'Die Rodelbahnliste wurde erfolgreich aktualisiert.'
+        except wrpylib.wrmwcache.UpdateCacheError as e:
+            if len(e.args) == 3: session['flash'] = u"Fehler bei Rodelbahn '{0}': {1}".format(e.args[1], e.args[2])
+            else: session['flash'] = unicode(e)
         session.save()
+        # Redirect to result page
         return redirect(url(controller='rodelbahn', action='list'))
+