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',
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__)
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):
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)
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__)
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)
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)
+
from authkit.users import UsersReadOnly, md5
import formencode, formencode.national
+
import logging
log = logging.getLogger(__name__)
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
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'
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),
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)
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
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):
<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>
</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>
</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>
<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>
</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>
</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>
</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>
</tr>
<tr>
<th>Information</th>
- <td>${c.sledding.information}</td>
+ <td>${c.sledding.information_phone}</td>
</tr>
<tr>
<th>Forum-ID</th>