return RodelbahnboxValidator().from_python(sledrun)
+class GasthausboxDictConverter(formencode.Validator):
+ """Converts a dict with Gasthausbox properties to a Inn class. Does no validation."""
+
+ def to_python(self, value, state=None):
+ """value is a dict of properties. If state is an object with the attribute inn, this inn class will be populated or updated."""
+ props = value
+ if isinstance(state, object) and hasattr(state, 'inn'):
+ sledrun = state.sledrun
+ else:
+ class Inn(object):
+ pass
+ inn = Inn()
+ for k, v in props.iteritems():
+ if k == u'Position': inn.position_latitude, inn.position_longitude = v
+ elif k == u'Höhe': inn.position_elevation = v
+ elif k == u'Betreiber': inn.operator = v
+ elif k == u'Sitzplätze': inn.seats = v
+ elif k == u'Übernachtung': inn.overnight, inn.overnight_comment = v
+ elif k == u'Rauchfrei': inn.nonsmoker_area, inn.smoker_area = v
+ elif k == u'Rodelverleih': inn.sled_rental, inn.sled_rental_comment = v
+ elif k == u'Handyempfang': inn.mobile_provider = v
+ elif k == u'Homepage': inn.homepage = v
+ elif k == u'E-Mail': inn.email_list = v
+ elif k == u'Telefon': inn.phone_list = v
+ elif k == u'Bild': inn.image = v
+ elif k == u'Rodelbahnen': inn.sledding_list = v
+ return inn
+
+ def from_python(self, value, state=None):
+ """Converts an inn class to a dict of Gasthausbox properties. value is an Inn instance."""
+ inn = value
+ r = collections.OrderedDict()
+ r[u'Position'] = (inn.position_latitude, inn.position_longitude)
+ r[u'Höhe'] = inn.position_elevation
+ r[u'Betreiber'] = inn.operator
+ r[u'Sitzplätze'] = inn.seats
+ r[u'Übernachtung'] = (inn.overnight, inn.overnight_comment)
+ r[u'Rauchfrei'] = (inn.nonsmoker_area, inn.smoker_area)
+ r[u'Rodelverleih'] = (inn.sled_rental, inn.sled_rental_comment)
+ r[u'Handyempfang'] = inn.mobile_provider
+ r[u'Homepage'] = inn.homepage
+ r[u'E-Mail'] = inn.email_list
+ r[u'Telefon'] = inn.phone_list
+ r[u'Bild'] = inn.image
+ r[u'Rodelbahnen'] = inn.sledding_list
+ return r
+
+
def gasthausbox_to_inn(wikitext, inn=None):
"""Converts a inn wiki page containing a {{Gasthausbox}} to an inn.
raises a formencode.Invalid exception if an error occurs.