X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wradmin.git/blobdiff_plain/255c52bbff9518490afce8e94898901dfd907832..8640dc6683d139c73b4cc39bd5bce7c5ff69c7bc:/wradmin/controllers/rodelbahn.py diff --git a/wradmin/controllers/rodelbahn.py b/wradmin/controllers/rodelbahn.py index cd75bbe..017da74 100644 --- a/wradmin/controllers/rodelbahn.py +++ b/wradmin/controllers/rodelbahn.py @@ -1,6 +1,6 @@ import json import subprocess -import urllib.request +import urllib.request, urllib.error from collections import OrderedDict from typing import Optional, Tuple, List @@ -51,10 +51,20 @@ class RodelbahnController: abort(404) h = PylonsHelper() sledrun_json_url = h.sledrun_json_url(sledrun.page_title) - sledrun_json_page = urllib.request.urlopen(sledrun_json_url) + sledrun_json_page = urllib.request.urlopen(sledrun_json_url) # might raise urllib.error.HTTPError 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) + 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) + 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') @@ -150,7 +160,8 @@ class RodelbahnController: 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()) + sled_rental_description=sled_rental_description, operator=betreiber(), + sledrun_map_json=sledrun_map_json) def json_edit(self, sledrun_id): q = db.session.query(WrSledrunCache)