From ae4a94a1f054903761d8651f6c255dac8fba192a Mon Sep 17 00:00:00 2001 From: Philipp Spitzer Date: Sat, 20 Feb 2021 23:15:44 +0100 Subject: [PATCH 1/1] Json is now loaded with Ajax. --- wradmin/controllers/rodelbahn.py | 19 +++++++++---------- wradmin/template_helper.py | 6 +++--- wradmin/templates/json_editor.html | 6 ++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/wradmin/controllers/rodelbahn.py b/wradmin/controllers/rodelbahn.py index 345cbc1..a4c2a64 100644 --- a/wradmin/controllers/rodelbahn.py +++ b/wradmin/controllers/rodelbahn.py @@ -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""" diff --git a/wradmin/template_helper.py b/wradmin/template_helper.py index a35b234..f7fc01c 100644 --- a/wradmin/template_helper.py +++ b/wradmin/template_helper.py @@ -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): diff --git a/wradmin/templates/json_editor.html b/wradmin/templates/json_editor.html index fb82fb5..31ea653 100644 --- a/wradmin/templates/json_editor.html +++ b/wradmin/templates/json_editor.html @@ -232,15 +232,13 @@ // 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( -- 2.39.5