]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Changed scripts to prevent a server error resulting in empty sled cache list.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 28 Oct 2010 22:06:06 +0000 (22:06 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Thu, 28 Oct 2010 22:06:06 +0000 (22:06 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@616 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/wradmin/controllers/gasthaus.py
wradmin/wradmin/controllers/rodelbahn.py
wradmin/wradmin/lib/mediawiki.py

index e8459690eae482b9be73acdb335f55d69bc789c4..6f95d7b3df6c06c152310061d6ce2b90d412e672 100644 (file)
@@ -91,7 +91,7 @@ class GasthausController(BaseController):
                 inn = wikipage_to_wrinncache(inn.page_id, inn.page_title, inn.old_text)
                 inn.under_construction = c.execute(select([categorylinks], (categorylinks.c.cl_from==inn.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 formencode.Invalid, e: error_msg = u"Fehler bei Gasthaus '%s': " % inn.page_title + unicode_e(e)
+            except (RuntimeError, formencode.Invalid) as e: error_msg = u"Fehler bei Gasthaus '%s': " % inn.page_title + unicode_e(e)
         model.meta.Session.commit()
         
         # Redirect to result page
index 73cc528a4770f6a54bbebe5dc553e07d798175cc..46dbba41d9cc795033950451b4d3e68aae7e5665 100644 (file)
@@ -13,6 +13,9 @@ import formencode
 import re
 from wradmin.lib.mediawiki import wikipage_to_wrsleddingcache, unicode_e
 
+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):
@@ -99,24 +102,26 @@ class RodelbahnController(BaseController):
         from sqlalchemy.sql import select
         c = model.meta.Session.connection()
         
-        # 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 wrsleddingcache
-        c.execute(wrsleddingcache.delete())
-        
-        # Refill wrsleddingcache table
-        error_msg = ''
-        for sl in sledding_pages:
-            try: 
-                sl = wikipage_to_wrsleddingcache(sl.page_id, sl.page_title, sl.old_text)
-                sl.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
-                model.meta.Session.add(sl)
-            except formencode.Invalid, e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode_e(e)
-        model.meta.Session.commit()
+        # 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 wrsleddingcache
+            if i == 1: c.execute(wrsleddingcache.delete())
+            
+            # Refill wrsleddingcache table
+            error_msg = u''
+            for sl in sledding_pages:
+                try: 
+                    sl = wikipage_to_wrsleddingcache(sl.page_id, sl.page_title, sl.old_text)
+                    sl.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(sl)
+                except (RuntimeError, formencode.Invalid) as e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode_e(e)
+            if i == 1: model.meta.Session.commit()
         
         # Redirect to result page
         if error_msg == '': session['flash'] = u'Die Rodelbahnliste wurde erfolgreich aktualisiert.'
index 46823b6e0beff4674a15ba43af5fa34af9461015..7a29085e3b4f37020495cf1ab21f71889eb45d5a 100644 (file)
@@ -39,7 +39,7 @@ def unicode_e(exception):
     """Does "unicode(exception)" as it should be. This is a workaround for bug http://bugs.python.org/issue2517
     that is not fixed in python 2.5.2.
     Details of bug: "unicode(Exception(u'\xe4'))" raises an UnicodeEncodeError exception."""
-    if exception.message: return unicode(exception.message)
+    #if exception.message: return unicode(exception.message) # this bug is already fixed. TODO: Cleanup calls to unicode_e
     return unicode(exception)