From: philipp Date: Mon, 14 Feb 2011 21:12:47 +0000 (+0000) Subject: Changed the rodelbahn and gasthaus controllers to use the new update function in... X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wradmin.git/commitdiff_plain/179ec31775a3545e78535b600ee712092932d729 Changed the rodelbahn and gasthaus controllers to use the new update function in wrpylib.wrmwcache. git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@779 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- diff --git a/wradmin/setup.py b/wradmin/setup.py index fe2cfb5..94bac37 100644 --- a/wradmin/setup.py +++ b/wradmin/setup.py @@ -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', diff --git a/wradmin/wradmin/controllers/gasthaus.py b/wradmin/wradmin/controllers/gasthaus.py index fcbea1d..37c1c9c 100644 --- a/wradmin/wradmin/controllers/gasthaus.py +++ b/wradmin/wradmin/controllers/gasthaus.py @@ -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')) + diff --git a/wradmin/wradmin/controllers/rodelbahn.py b/wradmin/wradmin/controllers/rodelbahn.py index 106751e..02df026 100644 --- a/wradmin/wradmin/controllers/rodelbahn.py +++ b/wradmin/wradmin/controllers/rodelbahn.py @@ -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')) +