]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/lib/helpers.py
Additional cleanup.
[philipp/winterrodeln/wradmin.git] / wradmin / lib / helpers.py
diff --git a/wradmin/lib/helpers.py b/wradmin/lib/helpers.py
new file mode 100644 (file)
index 0000000..c2f5e92
--- /dev/null
@@ -0,0 +1,48 @@
+"""Helper functions
+
+Consists of functions to typically be used within templates, but also
+available to Controllers. This module is available to templates as 'h'.
+"""
+# Import helpers as desired, or define your own, ie:
+#from webhelpers.html.tags import checkbox, password
+
+from pylons import url
+import wrpylib.wrvalidators
+from webhelpers.html.tags import file, form, end_form, submit
+
+def wiki(page_title=None):
+    "Creates a link to the specified page in the www.winterrodeln.org wiki"
+    if page_title is None: page_title = 'Hauptseite'
+    return u'http://www.winterrodeln.org/wiki/' + page_title
+
+
+def forum(forum=None):
+    "Creates a link to the specified forum. If no id is given, a general link is created."
+    if forum is None: return u'http://winterrodeln-forum.org/'
+    return u'http://winterrodeln-forum.org/viewforum.php?f=%d' % forum
+
+
+def google_maps(latitude, longitude):
+    "Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"
+    return u"http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
+
+
+def bool(value):
+    "Takes a bool value and creates a German representation"
+    return wrpylib.wrvalidators.GermanBoolNone().from_python(value)
+
+
+def tristate_tuple(yes, no):
+    "Takes a German representation of a tristate value"
+    return wrpylib.wrvalidators.GermanTristateTuple().from_python((yes, no))
+
+
+def tristate_float(value):
+    "Takes a German representation of a tristate value"
+    return wrpylib.wrvalidators.GermanTristateFloat().from_python(value)
+
+
+def public_transport(value):
+    if isinstance(value, long): value = int(value)
+    return wrpylib.wrvalidators.GermanPublicTransport().from_python(value)
+