3 from genshi import HTML
4 from flask import url_for, get_flashed_messages
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 google_maps(self, latitude, longitude):
31 """Builds an URL like http://maps.google.at/maps?q=47.200607,11.260007"""
32 return "http://maps.google.at/maps?q=%.6f,%.6f" % (latitude, longitude)
34 def bool(self, value):
35 """Takes a bool value and creates a German representation"""
36 return wrpylib.wrvalidators.opt_bool_german_to_str(value)
38 def tristate_tuple(self, yes, no):
39 """Takes a German representation of a tristate value"""
40 return {(True, True): 'Teilweise', (True, False): 'Ja', (False, True): 'Nein'}.get((yes, no), None)
42 def tristate_float(self, value):
43 """Takes a German representation of a tristate value"""
44 return wrpylib.wrvalidators.opt_tristate_german_to_str(value)
46 def public_transport(self, value):
47 return wrpylib.wrvalidators.opt_public_transport_german_to_str(value)
50 class TemplateContext:
54 def render_genshi_template(template, **kwargs):
55 loader = genshi.template.TemplateLoader(os.path.join(os.path.dirname(__file__), 'templates'), auto_reload=True)
56 tmpl = loader.load(template)
57 genshi_kwargs = {'h': PylonsHelper(), 'HTML': HTML, 'get_flashed_messages': get_flashed_messages}
58 genshi_kwargs.update(kwargs)
59 return tmpl.generate(**genshi_kwargs).render('html', doctype='html')