From: philipp Date: Tue, 6 Jul 2010 20:06:12 +0000 (+0000) Subject: wradmin shoud now handle the 1.3 versions of the tables correctly. X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wradmin.git/commitdiff_plain/37b35fd4cbcaa4e12999222f92a2569b4ea43f41 wradmin shoud now handle the 1.3 versions of the tables correctly. git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@577 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- diff --git a/wradmin/setup.py b/wradmin/setup.py index 06bdc36..6e8a485 100644 --- a/wradmin/setup.py +++ b/wradmin/setup.py @@ -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', diff --git a/wradmin/wradmin/controllers/gasthaus.py b/wradmin/wradmin/controllers/gasthaus.py index 7127ebd..0381379 100644 --- a/wradmin/wradmin/controllers/gasthaus.py +++ b/wradmin/wradmin/controllers/gasthaus.py @@ -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) diff --git a/wradmin/wradmin/controllers/rodelbahn.py b/wradmin/wradmin/controllers/rodelbahn.py index 6b1b6dc..4a5ffb1 100644 --- a/wradmin/wradmin/controllers/rodelbahn.py +++ b/wradmin/wradmin/controllers/rodelbahn.py @@ -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) diff --git a/wradmin/wradmin/lib/helpers.py b/wradmin/wradmin/lib/helpers.py index 8693d70..585cd44 100644 --- a/wradmin/wradmin/lib/helpers.py +++ b/wradmin/wradmin/lib/helpers.py @@ -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) + diff --git a/wradmin/wradmin/lib/mediawiki.py b/wradmin/wradmin/lib/mediawiki.py index 269d7d6..913d870 100644 --- a/wradmin/wradmin/lib/mediawiki.py +++ b/wradmin/wradmin/lib/mediawiki.py @@ -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' diff --git a/wradmin/wradmin/model/__init__.py b/wradmin/wradmin/model/__init__.py index 2953011..4ae923f 100644 --- a/wradmin/wradmin/model/__init__.py +++ b/wradmin/wradmin/model/__init__.py @@ -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) diff --git a/wradmin/wradmin/model/validators.py b/wradmin/wradmin/model/validators.py index 31f8f2c..4a30db3 100644 --- a/wradmin/wradmin/model/validators.py +++ b/wradmin/wradmin/model/validators.py @@ -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): diff --git a/wradmin/wradmin/templates/gasthaus_list.html b/wradmin/wradmin/templates/gasthaus_list.html index f1cfe82..005a0a0 100644 --- a/wradmin/wradmin/templates/gasthaus_list.html +++ b/wradmin/wradmin/templates/gasthaus_list.html @@ -25,8 +25,7 @@ ID Name Höhe - Festnetz - Mobiltelefon + Telefon E-Mail Homepage Rauchfrei @@ -38,12 +37,11 @@ ${s.page_id} ${s.page_title} - ${s.height} - ${s.phone} - ${s.mobile_phone} - ${s.email} + ${s.position_elevation} + ${s.phone_list} + ${s.email_list} ${s.homepage} - ${h.tristate(s.nonsmoker_area, s.smoker_area)} + ${h.tristate_tuple(s.nonsmoker_area, s.smoker_area)} ${s.image} ${s.position_latitude} ${s.position_longitude} diff --git a/wradmin/wradmin/templates/gasthaus_view.html b/wradmin/wradmin/templates/gasthaus_view.html index 25de44c..48204fc 100644 --- a/wradmin/wradmin/templates/gasthaus_view.html +++ b/wradmin/wradmin/templates/gasthaus_view.html @@ -25,19 +25,15 @@ Höhe - ${c.inn.height} + ${c.inn.position_elevation} - Festnetz - ${c.inn.phone} - - - Mobiltelefon - ${c.inn.mobile_phone} + Telefon + ${c.inn.phone_list} E-Mail - ${c.inn.email} + ${c.inn.email_list} Homepage @@ -45,7 +41,7 @@ Rauchfrei - ${h.tristate(c.inn.nonsmoker_area, c.inn.smoker_area)} + ${h.tristate_tuple(c.inn.nonsmoker_area, c.inn.smoker_area)} Bild diff --git a/wradmin/wradmin/templates/rodelbahn_list.html b/wradmin/wradmin/templates/rodelbahn_list.html index eb77fe8..c052e6c 100644 --- a/wradmin/wradmin/templates/rodelbahn_list.html +++ b/wradmin/wradmin/templates/rodelbahn_list.html @@ -44,18 +44,18 @@ ${s.page_id} ${s.page_title} ${s.length} - ${s.walktime} - ${s.height_top} - ${s.height_bottom} - ${h.bool(s.walkup_separate)} + ${s.walkup_time} + ${s.top_elevation} + ${s.bottom_elevation} + ${h.tristate_float(s.walkup_separate)} ${h.bool(s.lift)} - ${h.bool(s.night_light)} + ${h.tristate_float(s.night_light)} ${h.bool(s.sled_rental)} - ${h.bool(s.public_transport)} + ${h.public_transport(s.public_transport)} ${s.image} ${s.position_latitude} ${s.position_longitude} - ${s.information} + ${s.information_phone} ${s.forum_id} ${h.bool(s.under_construction)} ${h.bool(s.show_in_overview)} diff --git a/wradmin/wradmin/templates/rodelbahn_view.html b/wradmin/wradmin/templates/rodelbahn_view.html index 52d7da4..ed91ddb 100644 --- a/wradmin/wradmin/templates/rodelbahn_view.html +++ b/wradmin/wradmin/templates/rodelbahn_view.html @@ -29,19 +29,19 @@ Gehzeit - ${c.sledding.walktime} + ${c.sledding.walkup_time} Höhe (oben) - ${c.sledding.height_top} + ${c.sledding.top_elevation} Höhe (unten) - ${c.sledding.height_bottom} + ${c.sledding.bottom_elevation} Aufstieg getrennt - ${h.bool(c.sledding.walkup_separate)} + ${h.tristate_float(c.sledding.walkup_separate)} Lift @@ -49,7 +49,7 @@ Licht - ${h.bool(c.sledding.night_light)} + ${h.tristate_float(c.sledding.night_light)} Rodelverleih @@ -57,7 +57,7 @@ Öffentliche Anreise - ${h.bool(c.sledding.public_transport)} + ${h.public_transport(c.sledding.public_transport)} Bild @@ -73,7 +73,7 @@ Information - ${c.sledding.information} + ${c.sledding.information_phone} Forum-ID