From 775692ed79e61c835c1b7ce15b0041640bed6de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 17 Mar 2010 00:17:58 +0100 Subject: Clean up --- index.py | 59 ++++------------------------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) (limited to 'index.py') diff --git a/index.py b/index.py index eda595c..9263ea5 100755 --- a/index.py +++ b/index.py @@ -1,64 +1,13 @@ #!/usr/bin/python -from __future__ import with_statement - -import os import web -import mako -from mako.lookup import TemplateLookup - -from functools import partial - -import helper - -APPDIR = os.path.dirname(os.path.abspath(__file__)) - -app = web.auto_application() - -def appdir (*args): - return os.path.join(APPDIR, *args) - -class Renderer: - def __init__ (self): - self.lookup = TemplateLookup(directories=[appdir('templates')], - module_directory = "/tmp/portato/", - input_encoding='utf-8', - output_encoding='utf-8', - format_exceptions = True) +import controller - def render (self, tpl, level = "pages" , **kwargs): - try: - t = self.get_tpl(tpl, level) - except mako.exceptions.TopLevelLookupException, e: - raise app.notfound(tpl) - - return t.render(h = helper, url = helper.url, w = web, **kwargs) - - __call__ = render - - def get_tpl (self, tpl, level): - return self.lookup.get_template(self.get_tpl_name(tpl, level)) - - def get_tpl_name (self, tpl, level): - if not tpl.endswith(".mako"): - tpl = tpl+".mako" - - return os.path.join(level, tpl) +urls = ( "/(.*)", "controller.Page") +app = web.application(urls, globals()) +app.notfound = controller.FourOhFour web.config.debug = True -render = Renderer() - -def FourOhFour(page): - return web.notfound(render("404", level = "", page = page)) - -app.notfound = FourOhFour - -class Handler (app.page): - path = "/(.*)" - def GET(self, name = '/'): - if not name or name == '/': name = 'index' - return render(name) - if __name__ == "__main__": app.run() -- cgit v1.2.3