]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/controllers/rodelbahn.py
Now rendering JSON map stored in the wiki.
[philipp/winterrodeln/wradmin.git] / wradmin / controllers / rodelbahn.py
index cd75bbe9ef8b608d5151b9603497161d6084588d..017da740225f4a1efabb851289fd3d725650c588 100644 (file)
@@ -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)