]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/genshi.py
Remove function render_genshi_template.
[philipp/winterrodeln/wradmin.git] / wradmin / genshi.py
index 94c6c195ae477ba04c178b9be487cf873d230c66..446c315fcc11253c8ee7862b5e96c15efa6fa0f2 100644 (file)
@@ -1,10 +1,16 @@
-import os
-import genshi.template
+from flask import url_for
+import wrpylib.wrvalidators
 
 
 class PylonsHelper:
-    def url(self, controller, action=None):
-        return ''
+    def url(self, filename=None, controller=None, action=None, **kwargs):
+        if filename is not None and filename.startswith('/'):
+            filename = filename[1:]
+            return url_for('static', filename=filename)
+        if controller == 'rodelbahn':
+            if action == 'index':
+                return url_for('index')
+        return url_for('{}_{}'.format(controller, action), **kwargs)
 
     def wiki(self, page_title=None):
         """Creates a link to the specified page in the www.winterrodeln.org wiki"""
@@ -12,21 +18,27 @@ class PylonsHelper:
             page_title = 'Hauptseite'
         return 'http://www.winterrodeln.org/wiki/' + page_title
 
-    def forum(self):
-        return ''
+    def forum(self, forum=None):
+        """Creates a link to the specified forum. If no id is given, a general link is created."""
+        if forum is None:
+            return 'http://winterrodeln-forum.org/'
+        return 'http://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
 
+    def google_maps(self, latitude, longitude):
+        """Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"""
+        return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
 
-class FakeSession:
-    def has_key(self, key):
-        return False
+    def bool(self, value):
+        """Takes a bool value and creates a German representation"""
+        return wrpylib.wrvalidators.opt_bool_german_to_str(value)
 
-    def save(self):
-        pass
+    def tristate_tuple(self, yes, no):
+        """Takes a German representation of a tristate value"""
+        return {(True, True): 'Teilweise', (True, False): 'Ja', (False, True): 'Nein'}.get((yes, no), None)
 
+    def tristate_float(self, value):
+        """Takes a German representation of a tristate value"""
+        return wrpylib.wrvalidators.opt_tristate_german_to_str(value)
 
-def render_genshi_template(template, **kwargs):
-    loader = genshi.template.TemplateLoader(os.path.join(os.path.dirname(__file__), 'templates'), auto_reload=True)
-    tmpl = loader.load(template)
-    genshi_kwargs = {'h': PylonsHelper(), 'session': FakeSession()}
-    genshi_kwargs.update(kwargs)
-    return tmpl.generate(**genshi_kwargs).render('html', doctype='html')
+    def public_transport(self, value):
+        return wrpylib.wrvalidators.opt_public_transport_german_to_str(value)