-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
class RodelbahnController:
def view(self, id):
"""Displays a sled run"""
q = db.session.query(WrSledrunCache)
- sledding = q.get(id)
- if sledding is None:
+ sledrun = q.get(id)
+ if sledrun is None:
abort(404)
q = db.session.query(WrReport)
q = q.filter_by(page_id=id).order_by(sa.sql.expression.desc(WrReport.id))
paginator = paginate.Page(q.all(), page=int(request.args.get('page', 1)),
url_maker=lambda page: url_for('rodelbahn_view', id=id, page=page),
items_per_page=25)
- return render_template('rodelbahn_view.html', sledding=sledding, paginator=paginator)
+ return render_template('rodelbahn_view.html', sledding=sledrun, paginator=paginator)
+
+ def json_edit(self, sledrun_id):
+ q = db.session.query(WrSledrunCache)
+ sledrun = q.get(sledrun_id)
+ if sledrun is None:
+ abort(404)
+ 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"""