3 from genshi import HTML
4 from flask import url_for
5 import wrpylib.wrvalidators
9 def url(self, filename=None, controller=None, action=None, **kwargs):
10 if filename is not None and filename.startswith('/'):
11 filename = filename[1:]
12 return url_for('static', filename=filename)
13 if controller == 'rodelbahn':
15 return url_for('index')
16 return url_for('{}_{}'.format(controller, action), **kwargs)
18 def wiki(self, page_title=None):
19 """Creates a link to the specified page in the www.winterrodeln.org wiki"""
20 if page_title is None:
21 page_title = 'Hauptseite'
22 return 'http://www.winterrodeln.org/wiki/' + page_title
24 def forum(self, forum=None):
25 """Creates a link to the specified forum. If no id is given, a general link is created."""
27 return 'http://winterrodeln-forum.org/'
28 return 'http://winterrodeln-forum.org/viewforum.php?f={}'.format(forum)
30 def bool(self, value):
31 """Takes a bool value and creates a German representation"""
32 return wrpylib.wrvalidators.opt_bool_german_to_str(value)
34 def tristate_float(self, value):
35 """Takes a German representation of a tristate value"""
36 return wrpylib.wrvalidators.opt_tristate_german_to_str(value)
38 def public_transport(self, value):
39 return wrpylib.wrvalidators.opt_public_transport_german_to_str(value)
43 def has_key(self, key):
50 def render_genshi_template(template, **kwargs):
51 loader = genshi.template.TemplateLoader(os.path.join(os.path.dirname(__file__), 'templates'), auto_reload=True)
52 tmpl = loader.load(template)
53 genshi_kwargs = {'h': PylonsHelper(), 'session': FakeSession(), 'HTML': HTML}
54 genshi_kwargs.update(kwargs)
55 return tmpl.generate(**genshi_kwargs).render('html', doctype='html')