1 from urllib.parse import quote_plus
3 from flask import url_for, current_app
4 import wrpylib.wrvalidators
8 def url(self, filename=None, controller=None, action=None, **kwargs):
9 if filename is not None and filename.startswith('/'):
10 filename = filename[1:]
11 return url_for('static', filename=filename)
12 if controller == 'rodelbahn':
14 return url_for('index')
15 return url_for('{}_{}'.format(controller, action), **kwargs)
17 def wiki(self, page_title=None):
18 """Creates a link to the specified page in the www.winterrodeln.org wiki"""
19 if page_title is None:
20 page_title = 'Hauptseite'
21 return current_app.config['MEDIAWIKI_WIKI'] + '/' + page_title
23 def forum(self, forum=None):
24 """Creates a link to the specified forum. If no id is given, a general link is created."""
26 return 'https://winterrodeln-forum.org/'
27 return 'https://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
29 def mediawiki_index_url(self):
30 return f'{current_app.config["MEDIAWIKI_ROOT"]}/index.php'
32 def sledrun_json_schema_url(self, raw: bool = True):
33 url = f'{self.mediawiki_index_url()}?title=Winterrodeln:Datenschema/Rodelbahn/V1.json'
38 def sledrun_json_url(self, page_title, raw: bool = True):
39 url = f'{self.mediawiki_index_url()}?title={quote_plus(page_title)}/Rodelbahn.json'
44 def google_maps(self, latitude, longitude):
45 """Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"""
46 return "https://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
48 def bool(self, value):
49 """Takes a bool value and creates a German representation"""
50 return wrpylib.wrvalidators.opt_bool_german_to_str(value)
52 def tristate_tuple(self, yes, no):
53 """Takes a German representation of a tristate value"""
54 return {(True, True): 'Teilweise', (True, False): 'Ja', (False, True): 'Nein'}.get((yes, no), None)
56 def tristate_float(self, value):
57 """Takes a German representation of a tristate value"""
58 return wrpylib.wrvalidators.opt_tristate_german_to_str(value)
60 def public_transport(self, value):
61 return wrpylib.wrvalidators.opt_public_transport_german_to_str(value)