import re
import wrpylib.wrmwmarkup
+import wrpylib.wrmwcache
log = logging.getLogger(__name__)
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'))
+
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):
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'))
+