#!/usr/bin/python2.7
# -*- coding: iso-8859-15 -*-
+import collections
import wrpylib.wrmwmarkup
import wrpylib.mwmarkup
import formencode
wrpylib.wrmwmarkup.sledrun_to_rodelbahnbox(sledrun, '1.3')
+def test_RodelbahnboxDictConverter():
+ v = wrpylib.wrmwmarkup.RodelbahnboxDictConverter()
+ class Sledrun(object):
+ pass
+ other = collections.OrderedDict([
+ (u'Position', (47.30982, 9.986508)),
+ (u'Position oben', (None, None)),
+ (u'Höhe oben', 1244),
+ (u'Position unten', (None, None)),
+ (u'Höhe unten', 806),
+ (u'Länge', 5045),
+ (u'Schwierigkeit', None),
+ (u'Lawinen', 3),
+ (u'Betreiber', None),
+ (u'Öffentliche Anreise', 6),
+ (u'Aufstieg möglich', True),
+ (u'Aufstieg getrennt', (0.0, None)),
+ (u'Gehzeit', 105),
+ (u'Aufstiegshilfe', (False, None)),
+ (u'Beleuchtungsanlage', (0.0, None)),
+ (u'Beleuchtungstage', (None, None)),
+ (u'Rodelverleih', (True, u'Ja')),
+ (u'Gütesiegel', None),
+ (u'Webauskunft', None),
+ (u'Telefonauskunft', u'+43-664-1808482 (Bergkristallhütte)'),
+ (u'Bild', u'Rodelbahn Bergkristallhütte 2009-03-03.jpg'),
+ (u'In Übersichtskarte', True),
+ (u'Forumid', 72)])
+ sledrun = v.to_python((other, Sledrun()))
+ assert sledrun.forum_id == 72
+ other2 = v.from_python(sledrun)
+ assert other == other2
+
def test_gasthausbox_to_inn():
wikitext = u'''{{Gasthausbox
"""
import re
import xml.etree.ElementTree
+import collections
import formencode
import wrpylib.wrvalidators
import wrpylib.mwmarkup
return start, end, sledrun
+class RodelbahnboxDictConverter(formencode.Validator):
+ """Converts a dict with Rodelbahnbox properties to a Sledrun class. Does no validation."""
+
+ def to_python(self, value, state=None):
+ """value is a tuple (props, sledrun) where the sledrun class will be populated or updated."""
+ props, sledrun = value
+ for k, v in props.iteritems():
+ if k == u'Position': sledrun.position_latitude, sledrun.position_longitude = v
+ elif k == u'Position oben': sledrun.top_latitude, sledrun.top_longitude = v
+ elif k == u'Höhe oben': sledrun.top_elevation = v
+ elif k == u'Position unten': sledrun.bottom_latitude, sledrun.bottom_longitude = v
+ elif k == u'Höhe unten': sledrun.bottom_elevation = v
+ elif k == u'Länge': sledrun.length = v
+ elif k == u'Schwierigkeit': sledrun.difficulty = v
+ elif k == u'Lawinen': sledrun.avalanches = v
+ elif k == u'Betreiber': sledrun.operator = v
+ elif k == u'Öffentliche Anreise': sledrun.public_transport = v
+ elif k == u'Aufstieg möglich': sledrun.walkup_possible = v
+ elif k == u'Aufstieg getrennt': sledrun.walkup_separate, sledrun.walkup_separate_comment = v
+ elif k == u'Gehzeit': sledrun.walkup_time = v
+ elif k == u'Aufstiegshilfe': sledrun.lift, sledrun.lift_details = v
+ elif k == u'Beleuchtungsanlage': sledrun.night_light, sledrun.night_light_comment = v
+ elif k == u'Beleuchtungstage': sledrun.night_light_days, sledrun.night_light_days_comment = v
+ elif k == u'Rodelverleih': sledrun.sled_rental, sledrun.sled_rental_comment = v
+ elif k == u'Gütesiegel': sledrun.cachet = v
+ elif k == u'Webauskunft': sledrun.information_web = v
+ elif k == u'Telefonauskunft': sledrun.information_phone = v
+ elif k == u'Bild': sledrun.image = v
+ elif k == u'In Übersichtskarte': sledrun.show_in_overview = v
+ elif k == u'Forumid': sledrun.forum_id = v
+ return sledrun
+
+ def from_python(self, value, state=None):
+ """Converts a sledrun class to a dict of Rodelbahnbox properties. value is a sledrun instance."""
+ sledrun = value
+ r = collections.OrderedDict()
+ r[u'Position'] = (sledrun.position_latitude, sledrun.position_longitude)
+ r[u'Position oben'] = (sledrun.top_latitude, sledrun.top_longitude)
+ r[u'Höhe oben'] = sledrun.top_elevation
+ r[u'Position unten'] = (sledrun.bottom_latitude, sledrun.bottom_longitude)
+ r[u'Höhe unten'] = sledrun.bottom_elevation
+ r[u'Länge'] = sledrun.length
+ r[u'Schwierigkeit'] = sledrun.difficulty
+ r[u'Lawinen'] = sledrun.avalanches
+ r[u'Betreiber'] = sledrun.operator
+ r[u'Öffentliche Anreise'] = sledrun.public_transport
+ r[u'Aufstieg möglich'] = sledrun.walkup_possible
+ r[u'Aufstieg getrennt'] = (sledrun.walkup_separate, sledrun.walkup_separate_comment)
+ r[u'Gehzeit'] = sledrun.walkup_time
+ r[u'Aufstiegshilfe'] = (sledrun.lift, sledrun.lift_details)
+ r[u'Beleuchtungsanlage'] = (sledrun.night_light, sledrun.night_light_comment)
+ r[u'Beleuchtungstage'] = (sledrun.night_light_days, sledrun.night_light_days_comment)
+ r[u'Rodelverleih'] = (sledrun.sled_rental, sledrun.sled_rental_comment)
+ r[u'Gütesiegel'] = sledrun.cachet
+ r[u'Webauskunft'] = sledrun.information_web
+ r[u'Telefonauskunft'] = sledrun.information_phone
+ r[u'Bild'] = sledrun.image
+ r[u'In Übersichtskarte'] = sledrun.show_in_overview
+ r[u'Forumid'] = sledrun.forum_id
+ return r
+
+
def sledrun_to_rodelbahnbox(sledrun, version):
"""Converts a sledrun class to the {{Rodelbahnbox}} representation.
The sledrun class has to have properties like position_latitude, ...