]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
wradmin shoud now handle the 1.3 versions of the tables correctly.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 6 Jul 2010 20:06:12 +0000 (20:06 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 6 Jul 2010 20:06:12 +0000 (20:06 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@577 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/setup.py
wradmin/wradmin/controllers/gasthaus.py
wradmin/wradmin/controllers/rodelbahn.py
wradmin/wradmin/lib/helpers.py
wradmin/wradmin/lib/mediawiki.py
wradmin/wradmin/model/__init__.py
wradmin/wradmin/model/validators.py
wradmin/wradmin/templates/gasthaus_list.html
wradmin/wradmin/templates/gasthaus_view.html
wradmin/wradmin/templates/rodelbahn_list.html
wradmin/wradmin/templates/rodelbahn_view.html

index 06bdc36d05ce5a01fada50467c5e1841dbdb8d3b..6e8a485839a32a060beedb4706b388ce4f27a63c 100644 (file)
@@ -7,7 +7,7 @@ except ImportError:
 
 setup(
     name='wradmin',
-    version='1.2.0',
+    version='1.3.0',
     description='Administrative Interface for Winterrodeln',
     author='Philipp Spitzer',
     author_email='philipp.spitzer@winterrodeln.org',
index 7127ebdde33e1e8600ee1f2daeff6bdde808ed94..03813793b9d52f747aae62f26e84a68dd0febb61 100644 (file)
@@ -11,7 +11,7 @@ import wradmin.model as model
 import sqlalchemy as sa
 import formencode
 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
+from wradmin.lib.mediawiki import wikipage_to_wrinncache, unicode_e
 
 log = logging.getLogger(__name__)
 
@@ -33,42 +33,42 @@ class GasthausController(BaseController):
         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': 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 formencode.Invalid(u"Unbekannte Eigenschaft der Gasthausbox: '%s' (mit Wert '%s')" % (key, value), value, None)
-        inn.under_construction = None
-        return inn
+    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': 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 formencode.Invalid(u"Unbekannte Eigenschaft der Gasthausbox: '%s' (mit Wert '%s')" % (key, value), value, None)
+        inn.under_construction = None
+        return inn
     
     
     def update(self):
@@ -88,7 +88,7 @@ class GasthausController(BaseController):
         error_msg = ''
         for inn in inn_pages:
             try: 
-                inn = self._wikipage_to_wrinncache(inn)
+                inn = wikipage_to_wrinncache(inn.page_id, inn.page_title, inn.old_text)
                 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 formencode.Invalid, e: error_msg = u"Fehler bei Gasthaus '%s': " % inn.page_title + unicode_e(e)
index 6b1b6dc37d2bfc9abb3eb4b0fdb443f87f207749..4a5ffb1d951d45f0d62020335bf6c561999d0fb9 100644 (file)
@@ -11,7 +11,7 @@ import wradmin.model as model
 import sqlalchemy as sa
 import formencode
 import re
-from wradmin.lib.mediawiki import wikipage_to_wrsleddingcache1_2
+from wradmin.lib.mediawiki import wikipage_to_wrsleddingcache, unicode_e
 
 log = logging.getLogger(__name__)
 
@@ -112,7 +112,7 @@ class RodelbahnController(BaseController):
         error_msg = ''
         for sl in sledding_pages:
             try: 
-                sl = wikipage_to_wrsleddingcache1_2(sl.page_id, sl.page_title, sl.old_text)
+                sl = wikipage_to_wrsleddingcache(sl.page_id, sl.page_title, sl.old_text)
                 sl.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
                 model.meta.Session.add(sl)
             except formencode.Invalid, e: error_msg = u"Fehler bei Rodelbahn '%s': " % sl.page_title + unicode_e(e)
index 8693d70be4e9985adfa7efc0a19a04fa2f1fba75..585cd4492e743ff173f1a3e92a2cc2cc84858b63 100644 (file)
@@ -29,9 +29,20 @@ def google_maps(latitude, longitude):
 
 def bool(value):
     "Takes a bool value and creates a German representation"
-    return wradmin.model.validators.GermanBool().from_python(value)
+    return wradmin.model.validators.GermanBoolNone().from_python(value)
 
 
-def tristate(yes, no):
+def tristate_tuple(yes, no):
     "Takes a German representation of a tristate value"
-    return wradmin.model.validators.GermanTristate().from_python((yes, no))
+    return wradmin.model.validators.GermanTristateTuple().from_python((yes, no))
+
+
+def tristate_float(value):
+    "Takes a German representation of a tristate value"
+    return wradmin.model.validators.GermanTristateFloat().from_python(value)
+
+
+def public_transport(value):
+    if isinstance(value, long): value = int(value)
+    return wradmin.model.validators.GermanPublicTransport().from_python(value)
+
index 269d7d626f8060bbda4674183df3251aa90a2b57..913d8701d4498203851299f441902f36ed8b1bca 100644 (file)
@@ -7,6 +7,7 @@ import re
 
 from authkit.users import UsersReadOnly, md5
 import formencode, formencode.national
+
 import logging
 log = logging.getLogger(__name__)
 
@@ -111,7 +112,7 @@ def wikipage_to_wrsleddingcache(page_id, page_title, page_text):
     regexp = re.compile(u"\{\{(Rodelbahnbox[^\}]*)\}\}", re.DOTALL)
     match = regexp.search(wikitext)
     if not match:
-        raise RuntimeError(_(u"No 'Rodelbahnbox' found"))
+        raise RuntimeError(u"Rodelbahnbox nicht gefunden")
     box = match.group(1)
     
     # Process Rodelbahnbox
@@ -120,11 +121,11 @@ def wikipage_to_wrsleddingcache(page_id, page_title, page_text):
         if property == u'Rodelbahnbox': continue
         key_value = property.split('=')
         if len(key_value) != 2:
-            raise RuntimeError(_(u"Property '%s' has unexpected format") % key_value)
+            raise RuntimeError(u"Die Eigenschaft '%s' hat ein unerwartetes Format." % key_value)
         key = key_value[0].strip()
         value = key_value[1].strip()
         if key in [u'Rodelbahnnummer', u'Lift']:
-            errors.append(_("Property '%s' is not supported anymore, see %s.") % (key, 'http://www.winterrodeln.org/wiki/Vorlage:Rodelbahnbox'))
+            errors.append("Eigenschaft '%s' wird nicht mehr unterstuetzt, siehe %s." % (key, 'http://www.winterrodeln.org/wiki/Vorlage:Rodelbahnbox'))
         elif key == u'Position': sl.position_latitude, sl.position_longitude = conv(model.validators.GeoNone().to_python, value, key) # '47.583333 N 15.75 E'
         elif key == u'Position oben': sl.top_latitude, sl.top_longitude = conv(model.validators.GeoNone().to_python, value, key) # '47.583333 N 15.75 E'
         elif key == u'Höhe oben': sl.top_elevation = conv(model.validators.UnsignedNone().to_python, value, key) # '2000'
index 29530118f3023c36dd8cfe310c7ee9039c29c885..4ae923f3fcfa10ada3e44fcf6788fe939003a5d0 100644 (file)
@@ -134,11 +134,7 @@ wrinncache_table =  sa.Table("wrinncache", meta.metadata,
     sa.Column("sled_rental_comment", types.Unicode(255)),
     sa.Column("mobile_provider", types.Unicode),
     sa.Column("homepage", types.Unicode(255)),
-    sa.Column("email", types.Unicode(255)),
-    sa.Column("email_comment", types.Unicode(255)),
     sa.Column("email_list", types.Unicode),
-    sa.Column("phone", types.Unicode(30)),
-    sa.Column("phone_comment", types.Unicode(255)),
     sa.Column("phone_list", types.Unicode),
     sa.Column("image", types.Unicode(255)),
     sa.Column("sledding_list", types.Unicode),
@@ -224,6 +220,3 @@ orm.mapper(WrReport, wrreport_table)
 orm.mapper(WrSleddingCache, wrsleddingcache_table)
 orm.mapper(WrInnCache, wrinncache_table)
 
-# Old tables
-orm.mapper(WrSleddingCache1_2, wrsleddingcache_table1_2)
-orm.mapper(WrInnCache1_2, wrinncache_table1_2)
index 31f8f2c1b6b76367eb53b0f4f14a1bac0154bb34..4a30db337711d2ed0ff0b3bcd220303d8b0bfa38 100644 (file)
@@ -571,6 +571,18 @@ class ValueCommentListNeinLoopNone(NoneValidator):
         NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList())))
 
 
+class PhoneNumber(formencode.FancyValidator):
+    """Telefonnumber in international format, e.g. u'+43-699-1234567'"""
+    def __init__(self, default_cc=43):
+        self.validator = formencode.national.InternationalPhoneNumber(default_cc=lambda: default_cc)
+
+    def to_python(self, value):
+        return unicode(self.validator.to_python(value))
+
+    def from_python(self, value):
+        return self.validator.from_python(value)
+
+
 class PhoneCommentListNeinLoopNone(NoneValidator):
     """List with semicolon-separated phone numbers in international format with optional comment or 'Nein' as string:
     u''                                                       <=> None
@@ -578,7 +590,7 @@ class PhoneCommentListNeinLoopNone(NoneValidator):
     u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456' <=> u'+43-699-1234567 (nicht nach 20:00 Uhr); +43-512-123456'
     """
     def __init__(self, comments_are_optional):
-        NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(formencode.national.InternationalPhoneNumber(default_cc=lambda: 43), comments_are_optional=comments_are_optional))))
+        NoneValidator.__init__(self, NeinValidator(Loop(ValueCommentList(PhoneNumber(default_cc=43), comments_are_optional=comments_are_optional))))
 
 
 class EmailCommentListNeinLoopNone(NoneValidator):
index f1cfe821c9174b489991c49b0539e32e1ce1362c..005a0a0c16d12dab94a216d4d34680fee5940771 100644 (file)
@@ -25,8 +25,7 @@
         <th>ID</th>
         <th>Name</th>
         <th>Höhe</th>
-        <th>Festnetz</th>
-        <th>Mobiltelefon</th>
+        <th>Telefon</th>
         <th>E-Mail</th>
         <th>Homepage</th>
         <th>Rauchfrei</th>
     <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.position_elevation}</td>
+        <td>${s.phone_list}</td>
+        <td>${s.email_list}</td>
         <td>${s.homepage}</td>
-        <td>${h.tristate(s.nonsmoker_area, s.smoker_area)}</td>
+        <td>${h.tristate_tuple(s.nonsmoker_area, s.smoker_area)}</td>
         <td><small>${s.image}</small></td>
         <td>${s.position_latitude}</td>
         <td>${s.position_longitude}</td>
index 25de44c3b83d5ddd48c2130cdcc52a724c01835d..48204fc608d2cb067debba158dad5ec1e6e3a494 100644 (file)
     </tr>
     <tr>
         <th>Höhe</th>
-        <td>${c.inn.height}</td>
+        <td>${c.inn.position_elevation}</td>
     </tr>
     <tr>
-        <th>Festnetz</th>
-        <td>${c.inn.phone}</td>
-    </tr>
-    <tr>
-        <th>Mobiltelefon</th>
-        <td>${c.inn.mobile_phone}</td>
+        <th>Telefon</th>
+        <td>${c.inn.phone_list}</td>
     </tr>
     <tr>
         <th>E-Mail</th>
-        <td>${c.inn.email}</td>
+        <td>${c.inn.email_list}</td>
     </tr>
     <tr>
         <th>Homepage</th>
@@ -45,7 +41,7 @@
     </tr>
     <tr>
         <th>Rauchfrei</th>
-        <td>${h.tristate(c.inn.nonsmoker_area, c.inn.smoker_area)}</td>
+        <td>${h.tristate_tuple(c.inn.nonsmoker_area, c.inn.smoker_area)}</td>
     </tr>
     <tr>
         <th>Bild</th>
index eb77fe898e6b1499d7e88ad9d03ee51c23c566ab..c052e6c707975b7a2dd9696b68c01f4c1d058b00 100644 (file)
         <td><a href="${h.url_for(controller='rodelbahn', action='view', id=s.page_id)}">${s.page_id}</a></td>
         <td>${s.page_title}</td>
         <td>${s.length}</td>
-        <td>${s.walktime}</td>
-        <td>${s.height_top}</td>
-        <td>${s.height_bottom}</td>
-        <td>${h.bool(s.walkup_separate)}</td>
+        <td>${s.walkup_time}</td>
+        <td>${s.top_elevation}</td>
+        <td>${s.bottom_elevation}</td>
+        <td>${h.tristate_float(s.walkup_separate)}</td>
         <td>${h.bool(s.lift)}</td>
-        <td>${h.bool(s.night_light)}</td>
+        <td>${h.tristate_float(s.night_light)}</td>
         <td>${h.bool(s.sled_rental)}</td>
-        <td>${h.bool(s.public_transport)}</td>
+        <td>${h.public_transport(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.information_phone}</td>
         <td>${s.forum_id}</td>
         <td>${h.bool(s.under_construction)}</td>
         <td>${h.bool(s.show_in_overview)}</td>
index 52d7da4fd9d27f3263e9a526f6c263712c4d2790..ed91ddb100cf67bbffc4fe43d4e79c9dbf686e92 100644 (file)
     </tr>
     <tr>
         <th>Gehzeit</th>
-        <td>${c.sledding.walktime}</td>
+        <td>${c.sledding.walkup_time}</td>
     </tr>
     <tr>
         <th>Höhe (oben)</th>
-        <td>${c.sledding.height_top}</td>
+        <td>${c.sledding.top_elevation}</td>
     </tr>
     <tr>
         <th>Höhe (unten)</th>
-        <td>${c.sledding.height_bottom}</td>
+        <td>${c.sledding.bottom_elevation}</td>
     </tr>
     <tr>
         <th>Aufstieg getrennt</th>
-        <td>${h.bool(c.sledding.walkup_separate)}</td>
+        <td>${h.tristate_float(c.sledding.walkup_separate)}</td>
     </tr>
     <tr>
         <th>Lift</th>
@@ -49,7 +49,7 @@
     </tr>
     <tr>
         <th>Licht</th>
-        <td>${h.bool(c.sledding.night_light)}</td>
+        <td>${h.tristate_float(c.sledding.night_light)}</td>
     </tr>
     <tr>
         <th>Rodelverleih</th>
@@ -57,7 +57,7 @@
     </tr>
     <tr>
         <th>Öffentliche Anreise</th>
-        <td>${h.bool(c.sledding.public_transport)}</td>
+        <td>${h.public_transport(c.sledding.public_transport)}</td>
     </tr>
     <tr>
         <th>Bild</th>
@@ -73,7 +73,7 @@
     </tr>
     <tr>
         <th>Information</th>
-        <td>${c.sledding.information}</td>
+        <td>${c.sledding.information_phone}</td>
     </tr>
     <tr>
         <th>Forum-ID</th>