]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blob - wradmin/lib/helpers.py
3e0247cbfe61bf593225a5e29cf21d145a234654
[philipp/winterrodeln/wradmin.git] / wradmin / lib / helpers.py
1 """Helper functions
2
3 Consists of functions to typically be used within templates, but also
4 available to Controllers. This module is available to templates as 'h'.
5 """
6 # Import helpers as desired, or define your own, ie:
7 #from webhelpers.html.tags import checkbox, password
8
9 from pylons import url
10 import wrpylib.wrvalidators
11 from webhelpers.html.tags import file, form, end_form, submit
12
13 def wiki(page_title=None):
14     "Creates a link to the specified page in the www.winterrodeln.org wiki"
15     if page_title is None: page_title = 'Hauptseite'
16     return 'http://www.winterrodeln.org/wiki/' + page_title
17
18
19 def forum(forum=None):
20     "Creates a link to the specified forum. If no id is given, a general link is created."
21     if forum is None: return 'http://winterrodeln-forum.org/'
22     return 'http://winterrodeln-forum.org/viewforum.php?f=%d' % forum
23
24
25 def google_maps(latitude, longitude):
26     "Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"
27     return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
28
29
30 def bool(value):
31     "Takes a bool value and creates a German representation"
32     return wrpylib.wrvalidators.GermanBoolNone().from_python(value)
33
34
35 def tristate_tuple(yes, no):
36     "Takes a German representation of a tristate value"
37     return wrpylib.wrvalidators.GermanTristateTuple().from_python((yes, no))
38
39
40 def tristate_float(value):
41     "Takes a German representation of a tristate value"
42     return wrpylib.wrvalidators.GermanTristateFloat().from_python(value)
43
44
45 def public_transport(value):
46     if isinstance(value, int): value = int(value)
47     return wrpylib.wrvalidators.GermanPublicTransport().from_python(value)
48