diff -r 96d551b90734 -r 2c66ab45d91e pvl/web/application.py --- a/pvl/web/application.py Mon Jan 21 18:39:53 2013 +0200 +++ b/pvl/web/application.py Mon Jan 21 18:40:09 2013 +0200 @@ -10,14 +10,17 @@ class Application (object) : """ - Main state. + Main wsgi entry point state. """ URLS = None - def __init__ (self, urls=None) : + # TODO: charset + + def __init__ (self, urls=None, layout=None) : """ urls - werkzeug.routing.Map -> Handler + layout - template with {TITLE} and {HEAD} and {BODY} """ if not urls : @@ -25,7 +28,8 @@ if not urls : raise ValueError("No URLS/urls=... given") - + + self.layout = layout self.urls = urls def respond (self, request) : @@ -121,22 +125,33 @@ """ title = self.title() - - return html.html( - html.head( - html.title(title), + head = html( ( html.link(rel='Stylesheet', type="text/css", href=src) for src in self.CSS ), ( html.script(src=src, type='text/javascript', _selfclosing=False) for src in self.JS ), - ), - html.body( - html.h1(title), - self.render() + ) + body = html(self.render()) + + if self.app.layout : + return self.app.layout.format( + TITLE = unicode(title), + HEAD = unicode(head), + BODY = unicode(body), ) - ) + else : + return html.document(html.html( + html.head( + html.title(title), + head, + ), + html.body( + html.h1(title), + body, + ) + )) def process (self, **params) : """ @@ -159,8 +174,7 @@ return response # render as html per default - render = self.render_html() - text = unicode(html.document(render)) + text = unicode(self.render_html()) return Response(text, mimetype='text/html')