]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Added functionality to show inns. Solved to problem that database connections were...
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 28 Mar 2009 15:14:41 +0000 (15:14 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 28 Mar 2009 15:14:41 +0000 (15:14 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@435 7aebc617-e5e2-0310-91dc-80fb5f6d2477

15 files changed:
wradmin/development.ini
wradmin/wradmin/controllers/bericht.py
wradmin/wradmin/controllers/gasthaus.py [new file with mode: 0644]
wradmin/wradmin/lib/base.py
wradmin/wradmin/lib/helpers.py
wradmin/wradmin/lib/mediawiki.py
wradmin/wradmin/lib/wrcachelists.py
wradmin/wradmin/lib/wrdatabase.py
wradmin/wradmin/model/__init__.py
wradmin/wradmin/model/meta.py
wradmin/wradmin/templates/gasthaus_list.html [new file with mode: 0644]
wradmin/wradmin/templates/gasthaus_view.html [new file with mode: 0644]
wradmin/wradmin/templates/index.html
wradmin/wradmin/templates/master.html
wradmin/wradmin/templates/rodelbahn_list.html

index a8c4d63e950bb2c3f8b124f46e2a2d93534859c6..7edb92e54f0f31e686acedfef4b2125893e43794 100644 (file)
@@ -45,6 +45,8 @@ authkit.basic.authenticate.user.data =
 sqlalchemy.url = mysql://philipp@localhost:3306/winterrodeln_wiki?charset=utf8
 # necessary for mySQL databases
 sqlalchemy.pool_recycle = 3600
+# sqlalchemy.echo_pool = 1
+# sqlalchemy.echo=true
 
 # WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
 # Debug mode will enable the interactive debugging tool, allowing ANYONE to
index 63f8ab873570d3d10c2a9910aec6c9e7abef5e6f..622c1da745e0a2046882e8729384e9759d8995ea 100644 (file)
@@ -57,7 +57,8 @@ class BerichtController(BaseController):
         c.date_two_weeks = now + datetime.timedelta(14)
         c.date_one_week_more = date_invalid + datetime.timedelta(7)
         c.date_end_of_saison = datetime.datetime(now.year, 7, 1)
-        
+    
+    
     def view(self, id):
         "Displays a report"
         q = model.meta.Session.query(model.WrReport)
@@ -66,6 +67,7 @@ class BerichtController(BaseController):
         self._add_dates_to_c(c.wrreport.date_invalid)
         return render('bericht_view.html')
     
+    
     @restrict('POST')
     @validate(schema=ChangeDateInvalidForm(), form='view')
     def change_date_invalid(self, id=None):
@@ -87,29 +89,35 @@ class BerichtController(BaseController):
         session.save()
         return redirect_to(controller='bericht', action='view', id=id)
     
+    
     def new(self, id):
         "Displays a form to create a new page"
         return u"Nicht implementiert."
     
+    
     def create(self):
         "Saves the information submitted from new() and redirects to view()"
         return u"Nicht implementiert."
     
+    
     def edit(self, id):
         "Displays a form for editing the page id"
         return u"Nicht implementiert."
     
+    
     def save(self, id):
         "Saves the page id and redirects to view()"
         return u"Nicht implementiert."
     
+    
     def list(self):
         "Lists all reports"
         q = model.meta.Session.query(model.WrReport)
         q = q.order_by(sa.sql.expression.desc(model.WrReport.id))
         c.paginator = paginate.Page(q, page=int(request.params.get('page', 1)), items_per_page = 25)
         return render('bericht_list.html')
-        
+    
+    
     def delete(self, id):
         "Deletes a page"
         return u"Nicht implementiert."
diff --git a/wradmin/wradmin/controllers/gasthaus.py b/wradmin/wradmin/controllers/gasthaus.py
new file mode 100644 (file)
index 0000000..73fd658
--- /dev/null
@@ -0,0 +1,101 @@
+#!/usr/bin/python2.5
+# -*- coding: iso-8859-15 -*-
+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+import webhelpers.paginate as paginate
+
+from wradmin.lib.base import BaseController, render
+import wradmin.model as model
+import sqlalchemy as sa
+import re
+from wradmin.lib.mediawiki import to_unsigned, to_date, to_geo, to_title, to_tristate, to_email, to_url, to_phone, conv, unicode_e
+
+log = logging.getLogger(__name__)
+
+class GasthausController(BaseController):
+
+    def list(self):
+        "Lists all inns"
+        q = model.meta.Session.query(model.WrInnCache)
+        q = q.order_by(model.WrInnCache.page_title)
+        c.paginator = paginate.Page(q, page=int(request.params.get('page', 1)), items_per_page = 25)
+        return render('gasthaus_list.html')
+    
+    
+    def view(self, id):
+        "Displays an inn"
+        q = model.meta.Session.query(model.WrInnCache)
+        c.inn =  q.get(id)
+        if c.inn is None: abort(404)
+        return render('gasthaus_view.html')
+    
+    
+    def _wikipage_to_wrinncache(self, inn_wiki):
+        "Converts an inn wiki page to an inn wrinncache database record."
+        inn = model.WrInnCache()
+        inn.page_id = inn_wiki.page_id
+        inn.page_title = to_title(inn_wiki.page_title)
+        
+        # Match Gasthausbox
+        wikitext = inn_wiki.old_text
+        regexp = re.compile(u"\{\{(Gasthausbox[^\}]*)\}\}", re.DOTALL)
+        match = regexp.search(wikitext)
+        if not match:
+            raise Exception(u"No 'Gasthausbox' found")
+        box = match.group(1)
+        
+        # Process Gashausbox
+        for property in box.split('|'):
+            property = property.strip()
+            if property == u'Gasthausbox': continue
+            key_value = property.split('=')
+            if len(key_value) != 2:
+                raise Exception(u"Property '%s' has unexpected format" % key_value)
+            key = key_value[0].strip()
+            value = key_value[1].strip()
+            if key == u'Gasthausnummer': pass
+            elif key == u'E-Mail': inn.email = conv(to_email, value, u'E-Mail')
+            elif key == u'Homepage': inn.homepage = conv(to_url, value, u'Homepage')
+            elif key == u'Höhe':
+                if value: inn.height = conv(to_unsigned, value, u'Höhe')
+            elif key == u'Bild': inn.image = value
+            elif key == u'Position': (inn.position_latitude, inn.position_longitude) = conv(to_geo, value, u'Position') # '47.583333 N 15.75 E'
+            elif key == u'Telefon (Festnetz)': inn.phone = conv(to_phone, value, u'Telefon (Festnetz)')
+            elif key == u'Telefon (Mobil)': inn.mobile_phone = conv(to_phone, value, u'Telefon (Mobil)')
+            elif key == u'Rauchfrei': (inn.nonsmoker_area, inn.smoker_area) = conv(to_tristate, value, u'Rauchfrei')
+            elif key == u'Aufnahmedatum': inn.creation_date = conv(to_date, value, u'Aufnahmedatum') # '2006-03-15'
+            else: raise Exception(u"Unbekannte Eigenschaft der Rodelbahnbox: '%s' (mit Wert '%s')" % (key, value))
+        inn.under_construction = None
+        return inn
+    
+    
+    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 = ''
+        for inn in inn_pages:
+            try: 
+                inn = self._wikipage_to_wrinncache(inn)
+                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 Exception, e: error_msg = u"Fehler bei Gasthaus '%s': " % inn.page_title + unicode_e(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
+        session.save()
+        return redirect_to(controller='gasthaus', action='list')
index 936441e49fe196084cd49f325fa42c88d6a0de94..c1a36dc65674c682d38f3c062467262d642a7d3c 100644 (file)
@@ -4,6 +4,7 @@ Provides the BaseController class for subclassing.
 """
 from pylons.controllers import WSGIController
 from pylons.templating import render_genshi as render
+from wradmin.model import meta
 
 class BaseController(WSGIController):
 
@@ -12,4 +13,8 @@ class BaseController(WSGIController):
         # WSGIController.__call__ dispatches to the Controller method
         # the request is routed to. This routing information is
         # available in environ['pylons.routes_dict']
-        return WSGIController.__call__(self, environ, start_response)
+        try:
+            return WSGIController.__call__(self, environ, start_response)
+        finally:
+            meta.Session.remove()
+
index dd021b87881783481be53e50d57cbd11c84d3a2c..6ecfeab942ab8aff5dd0ba5236a1cb1252f164bf 100644 (file)
@@ -11,14 +11,27 @@ from routes import url_for
 def wiki(page_title=None):
     "TODO: Improve, escape, ..."
     if page_title is None: page_title = 'Hauptseite'
-    return 'http://www.winterrodeln.org/wiki/' + page_title
+    return u'http://www.winterrodeln.org/wiki/' + page_title
 
 
 def forum(forum=None):
     "forum ... id"
-    return 'http://winterrodeln-forum.org/'
+    return u'http://winterrodeln-forum.org/'
 
 
 def google_maps(latitude, longitude):
     "Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"
-    return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
+    return u"http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
+
+
+def bool(value):
+    if value is None: return None
+    if value: return u'Ja'
+    return u'Nein'
+
+
+def tristate(yes, no):
+    if yes is None or no is None: return None
+    if yes == no: return u'Teilweise'
+    if yes: return u'Ja'
+    if no: return u'Nein'
index 39c83098f904067ac0ef76ecf57d109836d00213..891233b4ae0425d33ea774839bee743560586c9d 100644 (file)
@@ -2,10 +2,88 @@
 
 from authkit.users import UsersReadOnly, md5
 from wradmin.lib.wrdatabase import get_wiki_connection
+import re
 
 import logging
 log = logging.getLogger(__name__)
 
+
+# Converter functions
+# -------------------
+
+def to_bool(value):
+    if not value: return None
+    if value == u'Ja': return True
+    if value == u'Nein': return False
+    raise Exception(u"'%s' is not a valid boolean value, use one of 'Ja' or 'Nein'" % value)
+
+
+def to_unsigned(value):
+    v = int(value)
+    if v < 0: raise Exception('The value %v has to be positive.')
+    return v
+
+
+def to_date(value):
+    return None #!!!! TODO
+
+
+def to_geo(value):
+    """Formats to coordinates '47.076207 N 11.453553 E' to the (latitude, longitude) tuplet."""
+    if not value: return (None, None)
+    r = re.match(u'(\d+\.\d+) N (\d+\.\d+) E', value)
+    if r is None: raise Exception(u"Coordinates '%s' have not a format like '47.076207 N 11.453553 E'" % value)
+    return (float(r.groups()[0]), float(r.groups()[1]))
+
+
+def to_title(value):
+    """Line 2237 of includes/Title.php says: $this->mTextform = str_replace( '_', ' ', $dbkey );
+    No not check for None because a missing title is an error"""
+    return value.replace(u'_', u' ')
+
+
+def to_tristate(value):
+    """Does the following conversion:
+    None         -> (None, None)
+    u'Ja'        -> (True, False)
+    u'Teilweise' -> (True,  True)
+    u'Nein'      -> (False, True)"""
+    if value is None: return (None, None)
+    elif value == u'Ja': return (True, False)
+    elif value == u'Nein': return (False, True)
+    elif value == u'Teilweise': return (True, True)
+    raise Exception(u"The value has to be one of 'Ja', 'Nein' or 'Teilweise', not '%s'" % value)
+
+
+def to_email(value):
+    return value #!!!! TODO
+
+
+def to_url(value):
+    return value #!!!! TODO
+
+
+def to_phone(value):
+    return value #!!!! TODO
+
+
+def conv(fnct, value, fieldname):
+    "Like one of the to_xxx functions (e.g. to_bool), but adds the field name to the error message"
+    try: return fnct(value)
+    except Exception, e: raise Exception(u"Conversion error in field '%s': %s" % (fieldname, unicode_e(e)))
+
+
+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)
+    return unicode(exception)
+
+
+# User management
+# ---------------
+
 class MediaWikiUsers(UsersReadOnly):
     def __init__(self, data=None, encrypt=None):
         UsersReadOnly.__init__(self, data, encrypt)
index 21b11916d6a3ccbb6d819b21d33525086dc0aa8e..6fc980ead643992f7d0d7e6c341a6a3c56499def 100644 (file)
@@ -12,153 +12,129 @@ import re
 # Converter functions
 # -------------------
 
-def to_bool(value):
-       if not value: return None
-       if value == u'Ja': return True
-       if value == u'Nein': return False
-       raise Exception(u"'%s' is not a valid boolean value, use one of 'Ja' or 'Nein'" % value)
-
-
-def to_geo(value):
-       """Formats to coordinates '47.076207 N 11.453553 E' to the (latitude, longitude) tuplet."""
-       if not value: return (None, None)
-       r = re.match(u'(\d+\.\d+) N (\d+\.\d+) E', value)
-       if r is None: raise Exception(u"Coordinates '%s' have not a format like '47.076207 N 11.453553 E'" % value)
-       return (float(r.groups()[0]), float(r.groups()[1]))
-
-def to_title(value):
-       """Line 2237 of includes/Title.php says: $this->mTextform = str_replace( '_', ' ', $dbkey );
-       No not check for None because a missing title is an error"""
-       return value.replace(u'_', u' ')
-
-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)
-       return unicode(exception)
+from wradmin.lib.mediawiki import to_bool, to_geo, to_title, unicode_e
 
 
 # Sledding run
 # ------------
 
 def update_rodelbahnbox():
-       """Collects information from the Rodelbahnbox wiki structures.
-       It stores them in the database in case of success and returns a list of tuples (page_id, page_title) of successfully processed pages.
-       It raises an exception in case of errors and does not change the database."""
-       
-       def to_bool_f(value, fieldname):
-               "Like 'to_bool' but adds the field name to the exception description"
-               try: return to_bool(value)
-               except Exception, e:
-                       raise Exception(u"Error converting to bool in field '%s': %s" % (fieldname, unicode_e(e)))
-       
-       def to_geo_f(value, fieldname):
-               "Like 'to_geo' but adds the field name to the exception description"
-               try: return to_geo(value)
-               except Exception, e:
-                       raise Exception(u"Error converting to geo-coordinates in field '%s': %s" % (fieldname, unicode_e(e)))
-       
-       def process_row(row):
-               "It converts a database row to a dictionary and performs checks."
-               (page_id, rev_id, old_id, page_title, old_text, under_construction) = row
-               page_title = unicode(page_title, 'UTF-8')
-               old_text = unicode(old_text, 'UTF-8')
-               # Initialize property dict
-               property_keys = [
-                       u'page_id',
-                       u'page_title',
-                       u'length',
-                       u'walktime',
-                       u'height_top',
-                       u'height_bottom',
-                       u'walkup_separate',
-                       u'lift',
-                       u'night_light',
-                       u'sledge_rental',
-                       u'public_transport',
-                       u'image',
-                       u'position_latitude',
-                       u'position_longitude',
-                       u'information',
-                       u'show_in_overview',
-                       u'creation_date']
-               properties = dict()
-               for property in property_keys:
-                       properties[property] = None
-               # Match Rodelbahnbox
-               match = regexp.search(old_text)
-               if not match:
-                       raise Exception(u"No 'Rodelbahnbox' found")
-               box = match.group(1)
-               # Process Rodelbahnbox
-               for property in box.split('|'):
-                       property = property.strip()
-                       if property == u'Rodelbahnbox': continue
-                       key_value = property.split('=')
-                       if len(key_value) != 2:
-                               raise Exception(u"Property '%s' has unexpected format" % key_value)
-                       key = key_value[0].strip()
-                       value = key_value[1].strip()
-                       if key == u'Rodelbahnnummer': pass
-                       elif key == u'Länge' and value: properties[u'length'] = int(value)
-                       elif key == u'Gehzeit' and value: properties[u'walktime'] = int(value)
-                       elif key == u'Höhe oben' and value: properties[u'height_top'] = int(value)
-                       elif key == u'Höhe unten' and value: properties[u'height_bottom'] = int(value)
-                       elif key == u'Aufstieg getrennt': properties[u'walkup_separate'] = to_bool_f(value, u'Aufstieg getrennt')
-                       elif key == u'Lift': properties['lift'] = to_bool_f(value, u'Lift')
-                       elif key == u'Beleuchtung': properties[u'night_light'] = to_bool_f(value, u'Beleuchtung')
-                       elif key == u'Rodelverleih': properties[u'sledge_rental'] = to_bool_f(value, u'Rodelverleih')
-                       elif key == u'Öffentliche Anreise': properties[u'public_transport'] = to_bool_f(value, u'Öffentliche Anreise')
-                       elif key == u'Bild': properties[u'image'] = value
-                       elif key == u'Position': (properties[u'position_latitude'], properties[u'position_longitude']) = to_geo_f(value, u'Position') # '47.583333 N 15.75 E'
-                       elif key == u'Auskunft': properties[u'information'] = value
-                       elif key == u'In Übersichtskarte': properties[u'show_in_overview']  = to_bool_f(value, u'In Übersichtskarte')
-                       elif key == u'Aufnahmedatum': properties[u'creation_date'] = value # '2006-03-15'
-               properties[u'page_id'] = page_id
-               properties[u'page_title'] = to_title(page_title)
-               properties[u'under_construction'] = under_construction
-               del properties[u'creation_date'] # this is not saved in the database yet
-               return properties
-       
-       
-       # Load database modul
-       import MySQLdb
-       import re
+    """Collects information from the Rodelbahnbox wiki structures.
+    It stores them in the database in case of success and returns a list of tuples (page_id, page_title) of successfully processed pages.
+    It raises an exception in case of errors and does not change the database."""
+    
+    def to_bool_f(value, fieldname):
+        "Like 'to_bool' but adds the field name to the exception description"
+        try: return to_bool(value)
+        except Exception, e:
+            raise Exception(u"Error converting to bool in field '%s': %s" % (fieldname, unicode_e(e)))
+    
+    def to_geo_f(value, fieldname):
+        "Like 'to_geo' but adds the field name to the exception description"
+        try: return to_geo(value)
+        except Exception, e:
+            raise Exception(u"Error converting to geo-coordinates in field '%s': %s" % (fieldname, unicode_e(e)))
+    
+    def process_row(row):
+        "It converts a database row to a dictionary and performs checks."
+        (page_id, rev_id, old_id, page_title, old_text, under_construction) = row
+        page_title = unicode(page_title, 'UTF-8')
+        old_text = unicode(old_text, 'UTF-8')
+        # Initialize property dict
+        property_keys = [
+            u'page_id',
+            u'page_title',
+            u'length',
+            u'walktime',
+            u'height_top',
+            u'height_bottom',
+            u'walkup_separate',
+            u'lift',
+            u'night_light',
+            u'sledge_rental',
+            u'public_transport',
+            u'image',
+            u'position_latitude',
+            u'position_longitude',
+            u'information',
+            u'show_in_overview',
+            u'creation_date']
+        properties = dict()
+        for property in property_keys:
+            properties[property] = None
+        # Match Rodelbahnbox
+        match = regexp.search(old_text)
+        if not match:
+            raise Exception(u"No 'Rodelbahnbox' found")
+        box = match.group(1)
+        # Process Rodelbahnbox
+        for property in box.split('|'):
+            property = property.strip()
+            if property == u'Rodelbahnbox': continue
+            key_value = property.split('=')
+            if len(key_value) != 2:
+                raise Exception(u"Property '%s' has unexpected format" % key_value)
+            key = key_value[0].strip()
+            value = key_value[1].strip()
+            if key == u'Rodelbahnnummer': pass
+            elif key == u'Länge' and value: properties[u'length'] = int(value)
+            elif key == u'Gehzeit' and value: properties[u'walktime'] = int(value)
+            elif key == u'Höhe oben' and value: properties[u'height_top'] = int(value)
+            elif key == u'Höhe unten' and value: properties[u'height_bottom'] = int(value)
+            elif key == u'Aufstieg getrennt': properties[u'walkup_separate'] = to_bool_f(value, u'Aufstieg getrennt')
+            elif key == u'Lift': properties['lift'] = to_bool_f(value, u'Lift')
+            elif key == u'Beleuchtung': properties[u'night_light'] = to_bool_f(value, u'Beleuchtung')
+            elif key == u'Rodelverleih': properties[u'sledge_rental'] = to_bool_f(value, u'Rodelverleih')
+            elif key == u'Öffentliche Anreise': properties[u'public_transport'] = to_bool_f(value, u'Öffentliche Anreise')
+            elif key == u'Bild': properties[u'image'] = value
+            elif key == u'Position': (properties[u'position_latitude'], properties[u'position_longitude']) = to_geo_f(value, u'Position') # '47.583333 N 15.75 E'
+            elif key == u'Auskunft': properties[u'information'] = value
+            elif key == u'In Übersichtskarte': properties[u'show_in_overview']  = to_bool_f(value, u'In Übersichtskarte')
+            elif key == u'Aufnahmedatum': properties[u'creation_date'] = value # '2006-03-15'
+        properties[u'page_id'] = page_id
+        properties[u'page_title'] = to_title(page_title)
+        properties[u'under_construction'] = under_construction
+        del properties[u'creation_date'] # this is not saved in the database yet
+        return properties
+    
+    
+    # Load database modul
+    import MySQLdb
+    import re
 
-       conn = get_wiki_connection()
-       cuo = conn.cursor() # cursor for output (out of the database)
-       cui = conn.cursor() # cursor for input (into the database)
-       
-       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"
-       cuo.execute(sql)
-       
-       regexp = re.compile(u"\{\{(Rodelbahnbox[^\}]*)\}\}", re.DOTALL)
-       try:
-               sledding_list = [];
-               for row in cuo:
-                       try:
-                               page_id = row[0]
-                               page_title = unicode(row[3], 'UTF-8')
-                               properties = process_row(row)
-                       except Exception, e:
-                               raise Exception(unicode_e(e) + u". Seite '%s' (page_id %d)." % (page_title, page_id))
-                       sledding_list.append(properties)
-               
-               sql = u'delete from wrsleddingcache'
-               cui.execute(sql)
-               
-               if len(sledding_list) > 0:
-                       columns = sledding_list[0].keys()
-                       sql = u'insert into wrsleddingcache (' + ', '.join(columns)  + ') values '
-                       sql = sql + '(' + ', '.join(['%s' for c in columns]) + ')'
-                       for sledding in sledding_list:
-                               cui.execute(sql, sledding.values())
+    conn = get_wiki_connection()
+    cuo = conn.cursor() # cursor for output (out of the database)
+    cui = conn.cursor() # cursor for input (into the database)
+    
+    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"
+    cuo.execute(sql)
+    
+    regexp = re.compile(u"\{\{(Rodelbahnbox[^\}]*)\}\}", re.DOTALL)
+    try:
+        sledding_list = [];
+        for row in cuo:
+            try:
+                page_id = row[0]
+                page_title = unicode(row[3], 'UTF-8')
+                properties = process_row(row)
+            except Exception, e:
+                raise Exception(unicode_e(e) + u". Seite '%s' (page_id %d)." % (page_title, page_id))
+            sledding_list.append(properties)
+        
+        sql = u'delete from wrsleddingcache'
+        cui.execute(sql)
+        
+        if len(sledding_list) > 0:
+            columns = sledding_list[0].keys()
+            sql = u'insert into wrsleddingcache (' + ', '.join(columns)  + ') values '
+            sql = sql + '(' + ', '.join(['%s' for c in columns]) + ')'
+            for sledding in sledding_list:
+                cui.execute(sql, sledding.values())
 
-               conn.commit()
-               conn.close()
-       except:
-               conn.rollback()
-               conn.close()
-               raise
-       return sledding_list
\ No newline at end of file
+        conn.commit()
+        conn.close()
+    except:
+        conn.rollback()
+        conn.close()
+        raise
+    return sledding_list
\ No newline at end of file
index b36af72000d176ccdf6cc1e47faa7aa7e0e92984..429008b05df8300724ea9f5893ffa2a472ded258 100644 (file)
@@ -5,18 +5,18 @@ import MySQLdb
 from pylons import config
 
 def get_wiki_connection():
-       "Returns a connection object to the wiki database."
-       host = config['wikidbserver']
-       database = config['wikidbname']
-       username = config['wikidbuser']
-       password = config['wikidbpassword']
-       return MySQLdb.connect(host=host, db=database, user=username, passwd=password, use_unicode=True, charset='utf8')
+    "Returns a connection object to the wiki database."
+    host = config['wikidbserver']
+    database = config['wikidbname']
+    username = config['wikidbuser']
+    password = config['wikidbpassword']
+    return MySQLdb.connect(host=host, db=database, user=username, passwd=password, use_unicode=True, charset='utf8')
 
 
 def query_sledding_routes():
-       conn = get_wiki_connection()
-       cu = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
-       sql = "select page_id, rev_id, old_id, cast(page_title as char) as page_title, 'In_Arbeit' in (select cl_to from categorylinks where cl_from=page_id) as under_construction, page_id in (select tl_from from templatelinks where tl_title='Forumlink' and tl_namespace='10') as forum_link_present 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"
-       cu.execute(sql)
-       sledding_routes = cu.fetchall()
-       return sledding_routes
+    conn = get_wiki_connection()
+    cu = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
+    sql = "select page_id, rev_id, old_id, cast(page_title as char) as page_title, 'In_Arbeit' in (select cl_to from categorylinks where cl_from=page_id) as under_construction, page_id in (select tl_from from templatelinks where tl_title='Forumlink' and tl_namespace='10') as forum_link_present 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"
+    cu.execute(sql)
+    sledding_routes = cu.fetchall()
+    return sledding_routes
index d5d35dfd86be6c509d18c9273a733ec8003a83e5..f1839b0ab095855fbe454679e4d220437f835c09 100644 (file)
@@ -48,11 +48,74 @@ wrsleddingcache_table =  sa.Table("wrsleddingcache", meta.metadata,
     sa.Column("position_latitude", types.Float),
     sa.Column("position_longitude", types.Float),
     sa.Column("information", types.Unicode(255)),
+    sa.Column("forum_id", types.Integer),
     sa.Column("under_construction", types.Boolean),
     sa.Column("show_in_overview", types.Boolean),
     )
 
 
+wrinncache_table =  sa.Table("wrinncache", meta.metadata,
+    sa.Column("page_id", types.Integer, primary_key=True),
+    sa.Column("page_title", types.Unicode(255)),
+    sa.Column("height", types.Integer),
+    sa.Column("phone", types.Unicode(30)),
+    sa.Column("mobile_phone", types.Unicode(30)),
+    sa.Column("email", types.Unicode(255)),
+    sa.Column("homepage", types.Unicode(255)),
+    sa.Column("smoker_area", types.Boolean),
+    sa.Column("nonsmoker_area", types.Boolean),
+    sa.Column("image", types.Unicode(255)),
+    sa.Column("position_latitude", types.Float),
+    sa.Column("position_longitude", types.Float),
+    sa.Column("under_construction", types.Boolean),
+    )
+
+
+page_table = sa.Table("page", meta.metadata,
+    sa.Column("page_id", types.Integer, primary_key=True),
+    sa.Column("page_namespace", types.Integer, nullable=False),
+    sa.Column("page_title", types.Unicode(255), nullable=False),
+    sa.Column("page_restrictions", types.Unicode, nullable=False),
+    sa.Column("page_counter", types.Integer, nullable=False),
+    sa.Column("page_is_redirect", types.Integer, nullable=False),
+    sa.Column("page_is_new", types.Integer, nullable=False),
+    sa.Column("page_random", types.Float, nullable=False),
+    sa.Column("page_touched", types.Unicode(14), nullable=False),
+    sa.Column("page_latest", types.Integer, nullable=False),
+    sa.Column("page_len", types.Integer, nullable=False),
+    )
+
+
+revision_table = sa.Table("revision", meta.metadata,
+    sa.Column("rev_id", types.Integer, nullable=False, primary_key=True),
+    sa.Column("rev_page", types.Integer, nullable=False, primary_key=True),
+    sa.Column("rev_text_id", types.Integer, nullable=False),
+    sa.Column("rev_comment", types.Unicode),
+    sa.Column("rev_user", types.Integer, nullable=False),
+    sa.Column("rev_user_text", types.Unicode(255), nullable=False),
+    sa.Column("rev_timestamp", types.Unicode(14), nullable=False),
+    sa.Column("rev_minor_edit", types.Integer, nullable=False),
+    sa.Column("rev_deleted", types.Integer, nullable=False),
+    sa.Column("rev_len", types.Integer, nullable=False),
+    sa.Column("rev_parent_id", types.Integer, nullable=False),
+    )
+
+
+text_table = sa.Table("text", meta.metadata,
+    sa.Column("old_id", types.Integer, primary_key=True),
+    sa.Column("old_text", types.Unicode),
+    sa.Column("old_flags", types.Unicode),
+    )
+
+
+categorylinks_table = sa.Table("categorylinks", meta.metadata,
+    sa.Column("cl_from", types.Integer, nullable=False, primary_key=True),
+    sa.Column("cl_to", types.Unicode(255), nullable=False, primary_key=True),
+    sa.Column("cl_sortkey", types.Unicode, nullable=False),
+    sa.Column("cl_timestamp", types.DateTime, nullable=False),
+    )
+
+
 class WrReport(object):
     pass
 
@@ -61,8 +124,12 @@ class WrSleddingCache(object):
     pass
 
 
+class WrInnCache(object):
+    pass
+
+
 orm.mapper(WrReport, wrreport_table)
 # We could add a relation but we don't need it yet:
 # orm.mapper(WrSleddingCache, wrsleddingcache_table, properties = {'reports': orm.relation(WrReport, backref='sledding')})
 orm.mapper(WrSleddingCache, wrsleddingcache_table)
-
+orm.mapper(WrInnCache, wrinncache_table)
index 1a20aa7c693d42aa8ed607fbfd2d67d1d8d9b3f7..8ce61aa3b5091109fae3df300959c6edb1efc4af 100644 (file)
@@ -8,7 +8,7 @@ __all__ = ['Session', 'engine', 'metadata']
 engine = None
 
 # SQLAlchemy session manager. Updated by model.init_model()
-Session = scoped_session(sessionmaker())
+Session = scoped_session(sessionmaker(autoflush=True, autocommit=False))
 
 # Global metadata. If you have multiple databases with overlapping table
 # names, you'll need a metadata for each database
diff --git a/wradmin/wradmin/templates/gasthaus_list.html b/wradmin/wradmin/templates/gasthaus_list.html
new file mode 100644 (file)
index 0000000..f1cfe82
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:py="http://genshi.edgewall.org/"
+    xmlns:xi="http://www.w3.org/2001/XInclude">
+<xi:include href="master.html" />
+
+<head>
+    <title>Gasthäuser</title>
+</head>
+
+<body>
+<h2>Gasthäuser</h2>
+
+<p>Die folgende Lise wurde automatisiert von den Gasthausboxen gesammelt. Da dies nicht automatisch passiert, kann es sein, dass die Liste "veraltete" Information enthält.</p>
+
+<p><a href="${h.url_for(controller='gasthaus', action='update')}" class="button">Gasthausboxen auslesen und DB aktualisieren</a></p>
+
+
+<p>${c.paginator.pager('$link_first $link_previous $first_item bis $last_item von $item_count $link_next $link_last', controller='gasthaus', action='list')}</p>
+
+<table>
+    <tr>
+        <th>ID</th>
+        <th>Name</th>
+        <th>Höhe</th>
+        <th>Festnetz</th>
+        <th>Mobiltelefon</th>
+        <th>E-Mail</th>
+        <th>Homepage</th>
+        <th>Rauchfrei</th>
+        <th>Bild</th>
+        <th>Latitude</th>
+        <th>Longitude</th>
+        <th>In Arbeit</th>
+    </tr>
+    <tr py:for="s in c.paginator">
+        <td><a href="${h.url_for(controller='gasthaus', action='view', id=s.page_id)}">${s.page_id}</a></td>
+        <td>${s.page_title}</td>
+        <td>${s.height}</td>
+        <td>${s.phone}</td>
+        <td>${s.mobile_phone}</td>
+        <td>${s.email}</td>
+        <td>${s.homepage}</td>
+        <td>${h.tristate(s.nonsmoker_area, s.smoker_area)}</td>
+        <td><small>${s.image}</small></td>
+        <td>${s.position_latitude}</td>
+        <td>${s.position_longitude}</td>
+        <td>${h.bool(s.under_construction)}</td>
+    </tr>
+</table>
+
+<p>${c.paginator.pager('~2~', controller='gasthaus', action='list')}</p>
+
+</body>
+</html>
diff --git a/wradmin/wradmin/templates/gasthaus_view.html b/wradmin/wradmin/templates/gasthaus_view.html
new file mode 100644 (file)
index 0000000..25de44c
--- /dev/null
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:py="http://genshi.edgewall.org/"
+    xmlns:xi="http://www.w3.org/2001/XInclude">
+<xi:include href="master.html" />
+
+<head>
+    <title>Gasthaus</title>
+</head>
+
+<body>
+<h2>Gasthaus #${c.inn.page_id}: ${c.inn.page_title}</h2>
+
+<h3>Inhalt der Gasthausbox</h3>
+<table>
+    <tr>
+        <th>ID</th>
+        <td>${c.inn.page_id}</td>
+    </tr>
+    <tr>
+        <th>Name</th>
+        <td>${c.inn.page_title}</td>
+    </tr>
+    <tr>
+        <th>Höhe</th>
+        <td>${c.inn.height}</td>
+    </tr>
+    <tr>
+        <th>Festnetz</th>
+        <td>${c.inn.phone}</td>
+    </tr>
+    <tr>
+        <th>Mobiltelefon</th>
+        <td>${c.inn.mobile_phone}</td>
+    </tr>
+    <tr>
+        <th>E-Mail</th>
+        <td>${c.inn.email}</td>
+    </tr>
+    <tr>
+        <th>Homepage</th>
+        <td>${c.inn.homepage}</td>
+    </tr>
+    <tr>
+        <th>Rauchfrei</th>
+        <td>${h.tristate(c.inn.nonsmoker_area, c.inn.smoker_area)}</td>
+    </tr>
+    <tr>
+        <th>Bild</th>
+        <td>${c.inn.image}</td>
+    </tr>
+    <tr>
+        <th>Latitude</th>
+        <td>${c.inn.position_latitude}</td>
+    </tr>
+    <tr>
+        <th>Longitude</th>
+        <td>${c.inn.position_longitude}</td>
+    </tr>
+    <tr>
+        <th>In Arbeit</th>
+        <td>${c.inn.under_construction}</td>
+    </tr>
+</table>
+
+<ul>
+    <li><a href="${h.wiki(c.inn.page_title)}">Zeige bei <tt>www.winterrodeln.org</tt></a></li>
+    <py:if test="c.inn.position_latitude and c.inn.position_longitude">
+    <li><a href="${h.google_maps(c.inn.position_latitude, c.inn.position_longitude)}">Zeige bei Google Maps</a></li>
+    </py:if>
+</ul>
+
+
+</body>
+</html>
index 969a078a2874e8b5081f70603cd8977e6f234430..cb236e1b73c0aa955641be4b59383e30055ac7eb 100644 (file)
@@ -20,6 +20,7 @@
     <li><a href="${h.url_for(controller='rodelbahn', action='list')}">Rodelbahnen</a></li>
     <li><a href="${h.url_for(controller='bericht', action='list')}">Rodelbahnberichte</a></li>
     <li><a href="${h.url_for(controller='wrcontroller', action='rodelbahnbox')}">Rodelbahn-Infoboxen</a> überprüfen und Koordinaten aktualisieren</li>
+    <li><a href="${h.url_for(controller='gasthaus', action='list')}">Gasthäuser</a></li>
 </ul>
 
 <ul>
index 96d5e96296accd5e5e6a39562df2f93fadd34295..1fe1f06b9122c3970e9f63bb530004b159ed6b83 100644 (file)
@@ -27,6 +27,7 @@
     <li><a href="${h.url_for(controller='wrcontroller', action='rodelbahnbox')}">Rodelbahnboxen</a></li>
     <li><a href="${h.url_for(controller='bericht', action='list')}">Berichte</a></li>
     <li><a href="${h.url_for(controller='wrcontroller', action='forumlink')}">Forum-Links</a></li>
+    <li><a href="${h.url_for(controller='gasthaus', action='list')}">Gasthäuser</a></li>
 </ul>
 
 <div py:if="session.has_key('flash')" class="${session.pop('flashclass', 'flash')}">${session.pop('flash')}<?python session.save() ?></div>
index be4de35a24fd0f6644e4558e6e84a35a7bc4b7e3..f5e9cb9197940f6a34cdfdfbe8e03e98786cd086 100644 (file)
         <td>${s.walktime}</td>
         <td>${s.height_top}</td>
         <td>${s.height_bottom}</td>
-        <td>${s.walkup_separate}</td>
-        <td>${s.lift}</td>
-        <td>${s.night_light}</td>
-        <td>${s.sledge_rental}</td>
-        <td>${s.public_transport}</td>
+        <td>${h.bool(s.walkup_separate)}</td>
+        <td>${h.bool(s.lift)}</td>
+        <td>${h.bool(s.night_light)}</td>
+        <td>${h.bool(s.sledge_rental)}</td>
+        <td>${h.bool(s.public_transport)}</td>
         <td><small>${s.image}</small></td>
         <td>${s.position_latitude}</td>
         <td>${s.position_longitude}</td>
         <td>${s.information}</td>
-        <td>${s.under_construction}</td>
-        <td>${s.show_in_overview}</td>
+        <td>${h.bool(s.under_construction)}</td>
+        <td>${h.bool(s.show_in_overview)}</td>
     </tr>
 </table>