]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Json is now loaded with Ajax.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Sat, 20 Feb 2021 22:15:44 +0000 (23:15 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 21 Feb 2021 10:34:32 +0000 (11:34 +0100)
wradmin/controllers/rodelbahn.py
wradmin/template_helper.py
wradmin/templates/json_editor.html

index 345cbc113e27d9ec679d8c4a47b556dcae57a6fd..a4c2a6404a0e99ac98b3276921ee42e2ced594cb 100644 (file)
@@ -1,11 +1,12 @@
-from flask import request, abort, redirect, url_for, flash, render_template
+from urllib.parse import quote_plus
+
 import paginate
 import sqlalchemy as sa
+from flask import request, abort, redirect, url_for, flash, render_template, current_app
 
-import wrpylib.wrmwmarkup
-import wrpylib.wrmwcache
 import wrpylib.mwmarkup
-
+import wrpylib.wrmwcache
+import wrpylib.wrmwmarkup
 from wradmin.app import db
 from wradmin.model import WrSledrunCache, WrReport
 from wradmin.template_helper import PylonsHelper
@@ -40,12 +41,10 @@ class RodelbahnController:
         sledrun = q.get(sledrun_id)
         if sledrun is None:
             abort(404)
-        h = PylonsHelper()
-        return render_template('json_editor.html',
-                               schema_url=url_for('static', filename='schema_v1.json'),
-                               #json_url=url_for('static', filename='latschenhuette.json')
-                               json_url=h.wiki(sledrun.page_title)
-                               )
+        mediawiki_index = f'{current_app.config["MEDIAWIKI_ROOT"]}/index.php'
+        schema_url = f'{mediawiki_index}?title=Winterrodeln:Datenschema/Rodelbahn/V1.json&action=raw'
+        json_url = f'{mediawiki_index}?title={quote_plus(sledrun.page_title)}/Rodelbahn.json&action=raw'
+        return render_template('json_editor.html', schema_url=schema_url, json_url=json_url)
 
     def update(self):
         """Updates the wrsledruncache table from the wiki"""
index a35b2348ebd4380ba418c7130db4a3a2d86d6538..f7fc01c8eccd86b69afef85a824fe5efd222f892 100644 (file)
@@ -1,4 +1,4 @@
-from flask import url_for
+from flask import url_for, current_app
 import wrpylib.wrvalidators
 
 
@@ -16,12 +16,12 @@ class PylonsHelper:
         """Creates a link to the specified page in the www.winterrodeln.org wiki"""
         if page_title is None:
             page_title = 'Hauptseite'
-        return 'https://www.winterrodeln.org/wiki/' + page_title
+        return current_app.config['MEDIAWIKI_WIKI'] + '/' + page_title
 
     def forum(self, forum=None):
         """Creates a link to the specified forum. If no id is given, a general link is created."""
         if forum is None:
-            return 'http://winterrodeln-forum.org/'
+            return 'https://winterrodeln-forum.org/'
         return 'https://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
 
     def google_maps(self, latitude, longitude):
index fb82fb553fd07e3fa73a7710a7464c851bbb01af..31ea6536fad25f4529a6f9d0955af85a9fa80104 100644 (file)
 
     // Initialize the editor with a JSON schema
     var editor = new JSONEditor(document.getElementById('editor_holder'), {
-        // https://www.winterrodeln.org/mediawiki/index.php?title=Winterrodeln:Datenschema/Rodelbahn/V1.json&action=raw
-        schema: {"$ref": "{{schema_url}}"},
+        schema: {"$ref": {{schema_url|tojson}}},
         theme: 'bootstrap4',
         ajax: true
     });
 
     editor.on('ready',() => {
-        // https://www.winterrodeln.org/mediawiki/index.php?title=Latschenh%C3%BCtte/Rodelbahn.json&action=raw
-        fetch("{{json_url}}").then(
+        fetch({{json_url|tojson}}).then(
             function(response) {
                 return response.json();
             }).then(