]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/template_helper.py
Add links to JSON editing services for sledruns.
[philipp/winterrodeln/wradmin.git] / wradmin / template_helper.py
index 446c315fcc11253c8ee7862b5e96c15efa6fa0f2..b37571f761b6b314e9ed23affa2d1d914be88e1b 100644 (file)
@@ -1,4 +1,6 @@
-from flask import url_for
+from urllib.parse import quote_plus
+
+from flask import url_for, current_app
 import wrpylib.wrvalidators
 
 
@@ -16,17 +18,32 @@ class PylonsHelper:
         """Creates a link to the specified page in the www.winterrodeln.org wiki"""
         if page_title is None:
             page_title = 'Hauptseite'
-        return 'http://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 'http://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
+            return 'https://winterrodeln-forum.org/'
+        return 'https://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
+
+    def mediawiki_index_url(self):
+        return f'{current_app.config["MEDIAWIKI_ROOT"]}/index.php'
+
+    def sledrun_json_schema_url(self, raw: bool = True):
+        url = f'{self.mediawiki_index_url()}?title=Winterrodeln:Datenschema/Rodelbahn/V1.json'
+        if raw:
+            url += '&action=raw'
+        return url
+
+    def sledrun_json_url(self, page_title, raw: bool = True):
+        url = f'{self.mediawiki_index_url()}?title={quote_plus(page_title)}/Rodelbahn.json'
+        if raw:
+            url += '&action=raw'
+        return url
 
     def google_maps(self, latitude, longitude):
         """Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"""
-        return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
+        return "https://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
 
     def bool(self, value):
         """Takes a bool value and creates a German representation"""