pass
rodelbahnbox = collections.OrderedDict([
('Position', LonLat(9.986508, 47.30982)),
- ('Position oben', LonLat(None, None)),
+ ('Position oben', None),
('Höhe oben', 1244),
('Position unten', LonLat(8.506047, 46.20210)),
('Höhe unten', None),
class Inn:
pass
gasthausbox = collections.OrderedDict()
- gasthausbox['Position'] = LonLat(None, None)
+ gasthausbox['Position'] = None
gasthausbox['Höhe'] = None
gasthausbox['Betreiber'] = None
gasthausbox['Sitzplätze'] = None
inn.image = None
inn.sledding_list = 'Nein'
gasthausbox = inn_to_gasthausbox(inn)
- self.assertEqual(gasthausbox['Position'], LonLat(None, None))
+ self.assertEqual(gasthausbox['Position'], None)
self.assertEqual(gasthausbox['Höhe'], None)
self.assertEqual(gasthausbox['Betreiber'], None)
self.assertEqual(gasthausbox['Sitzplätze'], None)
class Inn:
pass
gasthausbox = collections.OrderedDict()
- gasthausbox['Position'] = LonLat(None, None)
+ gasthausbox['Position'] = None
gasthausbox['Höhe'] = None
gasthausbox['Betreiber'] = None
gasthausbox['Sitzplätze'] = None
inn.image = None
inn.sledding_list = None
gasthausbox = inn_to_gasthausbox(inn)
- self.assertEqual(gasthausbox['Position'], LonLat(None, None))
+ self.assertEqual(gasthausbox['Position'], None)
self.assertEqual(gasthausbox['Höhe'], None)
self.assertEqual(gasthausbox['Betreiber'], None)
self.assertEqual(gasthausbox['Sitzplätze'], None)
self.assertEqual(LonLat(12.806522, 46.807218), value['Position'])
self.assertEqual(LonLat(12.818658, 46.799014), value['Position oben'])
self.assertEqual(1046, value['Höhe oben'])
- self.assertEqual(LonLat(None, None), value['Position unten'])
+ self.assertEqual(None, value['Position unten'])
self.assertEqual(None, value['Höhe unten'])
self.assertEqual(3500, value['Länge'])
self.assertEqual(2, value['Schwierigkeit'])
('Position', LonLat(12.806522, 46.807218)),
('Position oben', LonLat(12.818658, 46.799014)),
('Höhe oben', 1046),
- ('Position unten', LonLat(None, None)),
+ ('Position unten', None),
('Höhe unten', None),
('Länge', 3500),
('Schwierigkeit', 2),
import re
import xml.etree.ElementTree
import collections
-from typing import Tuple, Optional, List
+from typing import Tuple, Optional, List, OrderedDict, Union
from mwparserfromhell.nodes import Template
opt_phone_comment_enum_to_str, lift_german_from_str, GASTHAUSBOX_DICT
-def sledrun_from_rodelbahnbox(value, sledrun):
+def split_lon_lat(value: Optional[LonLat]) -> Union[LonLat, Tuple[None, None]]:
+ if value is None:
+ return None, None
+ return value
+
+
+def join_lon_lat(lon: Optional[float], lat: Optional[float]) -> Optional[LonLat]:
+ if lon is None or lat is None:
+ return None
+ return LonLat(lon, lat)
+
+
+def sledrun_from_rodelbahnbox(value: OrderedDict, sledrun: object):
"""Takes a Rodelbahnbox as returned by rodelbahnbox_from_str (that is, an OrderedDict) and
updates the sledrun instance with all values present in the Rodelbahnbox. Other values are not
updated. Does not validate the arguments."""
# sledrun.page_id = None # this field is not updated because it is not present in the RodelbahnBox
# sledrun.page_title = None # this field is not updated because it is not present in the RodelbahnBox
# sledrun.name_url = None # this field is not updated because it is not present in the RodelbahnBox
- sledrun.position_longitude, sledrun.position_latitude = value['Position']
- sledrun.top_longitude, sledrun.top_latitude = value['Position oben']
+ sledrun.position_longitude, sledrun.position_latitude = split_lon_lat(value['Position'])
+ sledrun.top_longitude, sledrun.top_latitude = split_lon_lat(value['Position oben'])
sledrun.top_elevation = value['Höhe oben']
- sledrun.bottom_longitude, sledrun.bottom_latitude = value['Position unten']
+ sledrun.bottom_longitude, sledrun.bottom_latitude = split_lon_lat(value['Position unten'])
sledrun.bottom_elevation = value['Höhe unten']
sledrun.length = value['Länge']
sledrun.difficulty = value['Schwierigkeit']
"""Takes a sledrun instance that might come from the database and converts it to a OrderedDict ready
to be formatted as RodelbahnBox."""
value = collections.OrderedDict()
- value['Position'] = LonLat(sledrun.position_longitude, sledrun.position_latitude)
- value['Position oben'] = LonLat(sledrun.top_longitude, sledrun.top_latitude)
+ value['Position'] = join_lon_lat(sledrun.position_longitude, sledrun.position_latitude)
+ value['Position oben'] = join_lon_lat(sledrun.top_longitude, sledrun.top_latitude)
value['Höhe oben'] = sledrun.top_elevation
- value['Position unten'] = LonLat(sledrun.bottom_longitude, sledrun.bottom_latitude)
+ value['Position unten'] = join_lon_lat(sledrun.bottom_longitude, sledrun.bottom_latitude)
value['Höhe unten'] = sledrun.bottom_elevation
value['Länge'] = sledrun.length
value['Schwierigkeit'] = sledrun.difficulty
if v == '':
return None
return v
- inn.position_longitude, inn.position_latitude = value['Position']
+ inn.position_longitude, inn.position_latitude = split_lon_lat(value['Position'])
inn.position_elevation = value['Höhe']
inn.operator = value['Betreiber']
inn.seats = value['Sitzplätze']
def inn_to_gasthausbox(inn) -> collections.OrderedDict:
"""Converts an inn class to a dict of Gasthausbox properties. inn is an Inn instance."""
def convfromdb(val, key):
- v = '' if value is None else val
+ v = '' if val is None else val
return GASTHAUSBOX_DICT[key].from_str(v)
value = collections.OrderedDict()
- value['Position'] = LonLat(inn.position_longitude, inn.position_latitude)
+ value['Position'] = join_lon_lat(inn.position_longitude, inn.position_latitude)
value['Höhe'] = inn.position_elevation
value['Betreiber'] = inn.operator
value['Sitzplätze'] = inn.seats