except formencode.Invalid as e: raise formencode.Invalid(u"Conversion error in field '%s': %s" % (fieldname, unicode(e)), e.value, e.state)
-def rodelbahnbox_to_sledrun(wikitext, sledrun=None):
- """Converts a sledrun wiki page containing the {{Rodelbahnbox}}
- to a sledrun. sledrun may be an instance of WrSledrunCache or an "empty" class (object()) (default).
- Raises a formencode.Invalid exception if the format is not OK or the Rodelbahnbox is not found.
- :return: (start, end, sledrun) tuple of the Rodelbahnbox."""
- # find Rodelbahnbox
- start, end = wrpylib.mwmarkup.find_template(wikitext, u'Rodelbahnbox')
- if start is None: raise formencode.Invalid(u"Rodelbahnbox nicht gefunden", wikitext, None)
-
- # convert to sledrun
- if sledrun is None:
- state = None
- else:
- class State(object):
- pass
- state = State()
- state.sledrun = sledrun
- return start, end, RodelbahnboxValidator().to_python(wikitext[start:end], state)
-
-
class RodelbahnboxDictConverter(formencode.Validator):
"""Converts a dict with Rodelbahnbox properties to a Sledrun class. Does no validation."""
self.chained_validators = [RodelbahnboxDictConverter()]
+def rodelbahnbox_to_sledrun(wikitext, sledrun=None):
+ """Converts a sledrun wiki page containing the {{Rodelbahnbox}}
+ to a sledrun. sledrun may be an instance of WrSledrunCache or an "empty" class (object()) (default).
+ Raises a formencode.Invalid exception if the format is not OK or the Rodelbahnbox is not found.
+ :return: (start, end, sledrun) tuple of the Rodelbahnbox."""
+ # find Rodelbahnbox
+ start, end = wrpylib.mwmarkup.find_template(wikitext, u'Rodelbahnbox')
+ if start is None: raise formencode.Invalid(u"Rodelbahnbox nicht gefunden", wikitext, None)
+
+ # convert to sledrun
+ if sledrun is None:
+ state = None
+ else:
+ class State(object):
+ pass
+ state = State()
+ state.sledrun = sledrun
+ return start, end, RodelbahnboxValidator().to_python(wikitext[start:end], state)
+
+
def sledrun_to_rodelbahnbox(sledrun, version=None):
"""Converts a sledrun class to the {{Rodelbahnbox}} representation.
The sledrun class has to have properties like position_latitude, ...