]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Closed ticket #51: Title with umlauts caused an exception when errors occured in...
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 13 Mar 2009 21:38:27 +0000 (21:38 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 13 Mar 2009 21:38:27 +0000 (21:38 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@418 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/wradmin.egg-info/PKG-INFO
wradmin/wradmin.egg-info/SOURCES.txt
wradmin/wradmin/controllers/wrcontroller.py
wradmin/wradmin/lib/wrcachelists.py

index 458da230d3c7926ae698fe189a624b5e352fd3e7..82473d8e93ad1377632e6547f9577803a4b79ad5 100644 (file)
@@ -1,6 +1,6 @@
 Metadata-Version: 1.0
 Name: wradmin
-Version: 1.2.0dev-r415
+Version: 1.2.0dev-r417
 Summary: Administrative Interface for Winterrodeln
 Home-page: http://www.winterrodeln.org/
 Author: Philipp Spitzer
index f699ca07d1ffd6c7dbb6d28928c4076abbb4b85d..aba7b1a491af265a192bb089307254fabd71bdf7 100644 (file)
@@ -41,6 +41,7 @@ wradmin/public/favicon.ico
 wradmin/public/philipp_spitzer.png
 wradmin/public/style.css
 wradmin/public/titlebanner.png
+wradmin/public/white_transp.png
 wradmin/templates/__init__.py
 wradmin/templates/forumlink.html
 wradmin/templates/index.html
index 5b0ab4a7c41f5bf5866142897ae5d789f2aab4e3..c6f7cc29cf558bb06a108b80f4c9207fdcd4317c 100644 (file)
@@ -6,7 +6,7 @@ from pylons.templating import render_genshi as render
 
 from wradmin.lib.base import BaseController
 from wradmin.lib.wrdatabase import query_sledding_routes
-from wradmin.lib.wrcachelists import update_rodelbahnbox
+from wradmin.lib.wrcachelists import update_rodelbahnbox, unicode_e
 
 log = logging.getLogger(__name__)
 
@@ -19,8 +19,8 @@ class WrcontrollerController(BaseController):
                "update ... update the database from the Rodelbahnbox structures"
                if update:
                        try: c.sledding_routes = update_rodelbahnbox()
-                       except Exception, e: 
-                               c.update_error = e.message
+                       except Exception, e:
+                               c.update_error = unicode_e(e)
                c.update_performed = update
                c.update_success = hasattr(c, 'sledding_routes')
                return render('rodelbahnbox.html')
index ae21a35d5e0b20d2bf3844d1e057753c504970db..21b11916d6a3ccbb6d819b21d33525086dc0aa8e 100644 (file)
@@ -14,22 +14,29 @@ import re
 
 def to_bool(value):
        if not value: return None
-       if value == 'Ja': return True
-       if value == 'Nein': return False
-       raise Exception('%s is not a valid boolean value, use one of "Ja" or "Nein"' % value)
+       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('(\d+\.\d+) N (\d+\.\d+) E', value)
-       if r is None: raise Exception("Coordinates '%s' have not a format like '47.076207 N 11.453553 E'")
+       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('_', ' ')
+       """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)
 
 
 # Sledding run
@@ -44,13 +51,13 @@ def update_rodelbahnbox():
                "Like 'to_bool' but adds the field name to the exception description"
                try: return to_bool(value)
                except Exception, e:
-                       raise Exception("Error converting to bool in field %s: %s" % (fieldname, e.message))
+                       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("Error converting to geo-coordinates in field %s: %s" % (fieldname, e.message))
+                       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."
@@ -59,59 +66,59 @@ def update_rodelbahnbox():
                old_text = unicode(old_text, 'UTF-8')
                # Initialize property dict
                property_keys = [
-                       'page_id',
-                       'page_title',
-                       'length',
-                       'walktime',
-                       'height_top',
-                       'height_bottom',
-                       'walkup_separate',
-                       'lift',
-                       'night_light',
-                       'sledge_rental',
-                       'public_transport',
-                       'image',
-                       'position_latitude',
-                       'position_longitude',
-                       'information',
-                       'show_in_overview',
-                       'creation_date']
+                       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("No 'Rodelbahnbox' found")
+                       raise Exception(u"No 'Rodelbahnbox' found")
                box = match.group(1)
                # Process Rodelbahnbox
                for property in box.split('|'):
                        property = property.strip()
-                       if property == 'Rodelbahnbox': continue
+                       if property == u'Rodelbahnbox': continue
                        key_value = property.split('=')
                        if len(key_value) != 2:
-                               raise Exception("Property '%s' has unexpected format" % key_value)
+                               raise Exception(u"Property '%s' has unexpected format" % key_value)
                        key = key_value[0].strip()
                        value = key_value[1].strip()
-                       if key == 'Rodelbahnnummer': pass
-                       elif key == u'Länge' and value: properties['length'] = int(value)
-                       elif key == u'Gehzeit' and value: properties['walktime'] = int(value)
-                       elif key == u'Höhe oben' and value: properties['height_top'] = int(value)
-                       elif key == u'Höhe unten' and value: properties['height_bottom'] = int(value)
-                       elif key == u'Aufstieg getrennt': properties['walkup_separate'] = to_bool_f(value, u'Aufstieg getrennt')
+                       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['night_light'] = to_bool_f(value, u'Beleuchtung')
-                       elif key == u'Rodelverleih': properties['sledge_rental'] = to_bool_f(value, u'Rodelverleih')
-                       elif key == u'Öffentliche Anreise': properties['public_transport'] = to_bool_f(value, u'Öffentliche Anreise')
-                       elif key == u'Bild': properties['image'] = value
-                       elif key == u'Position': (properties['position_latitude'], properties['position_longitude']) = to_geo_f(value, u'Position') # '47.583333 N 15.75 E'
-                       elif key == u'Auskunft': properties['information'] = value
-                       elif key == u'In Übersichtskarte': properties['show_in_overview']  = to_bool_f(value, u'In Übersichtskarte')
-                       elif key == u'Aufnahmedatum': properties['creation_date'] = value # '2006-03-15'
-               properties['page_id'] = page_id
-               properties['page_title'] = to_title(page_title)
-               properties['under_construction'] = under_construction
-               del properties['creation_date'] # this is not saved in the database yet
+                       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
        
        
@@ -123,25 +130,27 @@ def update_rodelbahnbox():
        cuo = conn.cursor() # cursor for output (out of the database)
        cui = conn.cursor() # cursor for input (into the database)
        
-       sql = "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, %(pagecontent)s, 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" % {'pagecontent': "text"}
+       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("\{\{(Rodelbahnbox[^\}]*)\}\}", re.DOTALL)
+       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(e.message + '. Seite "%s" (page_id %d).' % (row[3], row[0]))
+                               raise Exception(unicode_e(e) + u". Seite '%s' (page_id %d)." % (page_title, page_id))
                        sledding_list.append(properties)
                
-               sql = 'delete from wrsleddingcache'
+               sql = u'delete from wrsleddingcache'
                cui.execute(sql)
                
                if len(sledding_list) > 0:
                        columns = sledding_list[0].keys()
-                       sql = 'insert into wrsleddingcache (' + ', '.join(columns)  + ') values '
+                       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())