]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/genshi.py
Adjust tests: Now all tests are passing.
[philipp/winterrodeln/wradmin.git] / wradmin / genshi.py
1 from flask import url_for
2 import wrpylib.wrvalidators
3
4
5 class PylonsHelper:
6     def url(self, filename=None, controller=None, action=None, **kwargs):
7         if filename is not None and filename.startswith('/'):
8             filename = filename[1:]
9             return url_for('static', filename=filename)
10         if controller == 'rodelbahn':
11             if action == 'index':
12                 return url_for('index')
13         return url_for('{}_{}'.format(controller, action), **kwargs)
14
15     def wiki(self, page_title=None):
16         """Creates a link to the specified page in the www.winterrodeln.org wiki"""
17         if page_title is None:
18             page_title = 'Hauptseite'
19         return 'http://www.winterrodeln.org/wiki/' + page_title
20
21     def forum(self, forum=None):
22         """Creates a link to the specified forum. If no id is given, a general link is created."""
23         if forum is None:
24             return 'http://winterrodeln-forum.org/'
25         return 'http://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
26
27     def google_maps(self, latitude, longitude):
28         """Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"""
29         return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
30
31     def bool(self, value):
32         """Takes a bool value and creates a German representation"""
33         return wrpylib.wrvalidators.opt_bool_german_to_str(value)
34
35     def tristate_tuple(self, yes, no):
36         """Takes a German representation of a tristate value"""
37         return {(True, True): 'Teilweise', (True, False): 'Ja', (False, True): 'Nein'}.get((yes, no), None)
38
39     def tristate_float(self, value):
40         """Takes a German representation of a tristate value"""
41         return wrpylib.wrvalidators.opt_tristate_german_to_str(value)
42
43     def public_transport(self, value):
44         return wrpylib.wrvalidators.opt_public_transport_german_to_str(value)