]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Added fieldnames to error messages in Rodelbahnbox parsing
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 8 Mar 2009 12:53:24 +0000 (12:53 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sun, 8 Mar 2009 12:53:24 +0000 (12:53 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@413 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/wradmin/lib/wrcachelists.py

index 6075a65732b5abf59382df8e3d2b17b3a727cafc..ae21a35d5e0b20d2bf3844d1e057753c504970db 100644 (file)
@@ -16,7 +16,7 @@ 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' % value)
+       raise Exception('%s is not a valid boolean value, use one of "Ja" or "Nein"' % value)
 
 
 def to_geo(value):
@@ -40,6 +40,18 @@ def update_rodelbahnbox():
        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("Error converting to bool in field %s: %s" % (fieldname, e.message))
+       
+       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))
+       
        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
@@ -69,7 +81,7 @@ def update_rodelbahnbox():
                        properties[property] = None
                # Match Rodelbahnbox
                match = regexp.search(old_text)
-               if not match: 
+               if not match:
                        raise Exception("No 'Rodelbahnbox' found")
                box = match.group(1)
                # Process Rodelbahnbox
@@ -86,15 +98,15 @@ def update_rodelbahnbox():
                        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(value)
-                       elif key == u'Lift': properties['lift'] = to_bool(value)
-                       elif key == u'Beleuchtung': properties['night_light'] = to_bool(value)
-                       elif key == u'Rodelverleih': properties['sledge_rental'] = to_bool(value)
-                       elif key == u'Öffentliche Anreise': properties['public_transport'] = to_bool(value)
+                       elif key == u'Aufstieg getrennt': properties['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(value) # '47.583333 N 15.75 E'
-                       elif key == u'Auskunft': properties['information'] = value 
-                       elif key == u'In Übersichtskarte': properties['show_in_overview']  = to_bool(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)