items_per_page=25)
return render_template('rodelbahn_view.html', sledding=sledrun, paginator=paginator)
- def view_wikitext(self, id):
+ def view_wikitext(self, id: int) -> str:
"""Displays a sled run as MediaWiki wiki text"""
q = db.session.query(WrSledrunCache)
sledrun = q.get(id)
sledrun_json_str = sledrun_json_page.read()
sledrun_json = json.loads(sledrun_json_str)
- sledrun_map_json = None
- sledrun_map_url = h.sledrun_map_url(sledrun.page_title)
+ map_json = None
+ map_url = h.sledrun_map_url(sledrun.page_title)
try:
- sledrun_map_page = urllib.request.urlopen(sledrun_map_url)
- sledrun_map_str = sledrun_map_page.read()
- sledrun_map_json = json.loads(sledrun_map_str)
+ map_page = urllib.request.urlopen(map_url)
+ map_str = map_page.read()
+ map_json = json.loads(map_str)
except urllib.error.HTTPError as e:
if e.code != 404: # accept "not found" as map not being present
raise
-
- def markdown_to_mediawiki(markdown: str) -> str:
- return subprocess.check_output(['pandoc', '--to', 'mediawiki'], input=markdown, encoding='utf-8')
-
- def position_to_lon_lat(value: Optional[dict]) -> Optional[LonLat]:
- if value is not None:
- lon = value.get('longitude')
- lat = value.get('latitude')
- if lon is not None and lat is not None:
- return LonLat(lon, lat)
- return None
-
- def position_ele_to_lon_lat(value: Optional[dict]) -> Optional[LonLat]:
- if value is not None:
- return position_to_lon_lat(value.get("position"))
- return None
-
- def position_ele_to_ele(value: Optional[dict]) -> Optional[int]:
- if value is not None:
- ele = value.get('elevation')
- if ele is not None:
- return int(ele)
- return None
-
- def aufstiegshilfe() -> Optional[List[Tuple[str, Optional[str]]]]:
- ws = sledrun_json.get('walkup_supports')
- if ws is None:
- return None
- return [(w['type'], w.get('comment')) for w in ws]
-
- def rodelverleih() -> Optional[List[Tuple[str, Optional[str]]]]:
- sr = sledrun_json.get('sled_rental_direct')
- if sr is None:
- return None
- return [('Ja', None)] if sr else []
-
- def webauskunft() -> Tuple[Optional[bool], Optional[str]]:
- info_web = sledrun_json.get('info_web')
- if info_web is None:
- return None, None
- if len(info_web) == 0:
- return False, None
- return True, info_web[0]['url']
-
- def telefonauskunft() -> Optional[List[Tuple[str, str]]]:
- info_phone = sledrun_json.get('info_phone')
- if info_phone is None:
- return None
- return [(pc['phone'], pc['name']) for pc in info_phone]
-
- def betreiber() -> str:
- has_operator = sledrun_json.get('has_operator')
- if has_operator is None:
- return sledrun_json.get('operator')
- if has_operator:
- return sledrun_json.get('operator')
- return 'Nein'
-
- sledrun_rbb_json = OrderedDict([
- ('Position', position_to_lon_lat(sledrun_json.get('position'))),
- ('Position oben', position_ele_to_lon_lat(sledrun_json.get('top'))),
- ('Höhe oben', position_ele_to_ele(sledrun_json.get('top'))),
- ('Position unten', position_ele_to_lon_lat(sledrun_json.get('bottom'))),
- ('Höhe unten', position_ele_to_ele(sledrun_json.get('bottom'))),
- ('Länge', sledrun_json.get('length')),
- ('Schwierigkeit', difficulty_german_from_str(sledrun_json.get('difficulty', ''))),
- ('Lawinen', avalanches_german_from_str(sledrun_json.get('avalanches', ''))),
- ('Betreiber', betreiber()),
- ('Öffentliche Anreise', public_transport_german_from_str(sledrun_json.get('public_transport', ''))),
- ('Aufstieg möglich', sledrun_json.get('walkup_possible')),
- ('Aufstieg getrennt', opt_tristate_german_comment_from_str(sledrun_json.get('walkup_separate', ''))),
- ('Gehzeit', sledrun_json.get('walkup_time')),
- ('Aufstiegshilfe', aufstiegshilfe()),
- ('Beleuchtungsanlage', opt_tristate_german_comment_from_str(sledrun_json.get('nightlight_possible'))),
- ('Beleuchtungstage', nightlightdays_from_str(sledrun_json.get('nightlight_weekdays', ''))),
- ('Rodelverleih', rodelverleih()),
- ('Gütesiegel', None),
- ('Webauskunft', webauskunft()),
- ('Telefonauskunft', telefonauskunft()),
- ('Bild', sledrun_json.get('image')),
- ('In Übersichtskarte', sledrun_json.get('show_in_overview')),
- ('Forumid', sledrun_json.get('forum_id'))
- ])
-
- def get_markdown_field(key: str) -> str:
- if key in sledrun_json:
- return markdown_to_mediawiki(sledrun_json[key])
- return ''
-
- description = get_markdown_field('description').strip()
- night_light = get_markdown_field('night_light').strip()
- sled_rental_description = get_markdown_field('sled_rental_description').strip()
-
- rodelbahnbox = rodelbahnbox_to_str(sledrun_rbb_json)
- return render_template('rodelbahn_view_wikitext.html', sledrun=sledrun, sledrun_json=sledrun_json,
- rodelbahnbox=rodelbahnbox, description=description, night_light=night_light,
- sled_rental_description=sled_rental_description, operator=betreiber(),
- sledrun_map_json=sledrun_map_json)
+ sledrun_wiki = wrpylib.wrmwmarkup.create_sledrun_wiki(sledrun_json=sledrun_json, map_json=map_json)
+ return render_template('rodelbahn_view_wikitext.html',
+ sledrun_name=sledrun.page_title, sledrun_wiki=sledrun_wiki)
def json_edit(self, sledrun_id):
q = db.session.query(WrSledrunCache)