]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/template_helper.py
b37571f761b6b314e9ed23affa2d1d914be88e1b
[philipp/winterrodeln/wradmin.git] / wradmin / template_helper.py
1 from urllib.parse import quote_plus
2
3 from flask import url_for, current_app
4 import wrpylib.wrvalidators
5
6
7 class PylonsHelper:
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':
13             if action == 'index':
14                 return url_for('index')
15         return url_for('{}_{}'.format(controller, action), **kwargs)
16
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
22
23     def forum(self, forum=None):
24         """Creates a link to the specified forum. If no id is given, a general link is created."""
25         if forum is None:
26             return 'https://winterrodeln-forum.org/'
27         return 'https://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
28
29     def mediawiki_index_url(self):
30         return f'{current_app.config["MEDIAWIKI_ROOT"]}/index.php'
31
32     def sledrun_json_schema_url(self, raw: bool = True):
33         url = f'{self.mediawiki_index_url()}?title=Winterrodeln:Datenschema/Rodelbahn/V1.json'
34         if raw:
35             url += '&action=raw'
36         return url
37
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'
40         if raw:
41             url += '&action=raw'
42         return url
43
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)
47
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)
51
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)
55
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)
59
60     def public_transport(self, value):
61         return wrpylib.wrvalidators.opt_public_transport_german_to_str(value)