summaryrefslogtreecommitdiff
path: root/index.py
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-11-25 22:49:43 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-11-25 22:49:43 +0100
commit492433abe865220c227e62cf12f3c93856432585 (patch)
treec33d0562c3c1c2dfde298eb083d5fd39c5fe8984 /index.py
downloadweb-492433abe865220c227e62cf12f3c93856432585.tar.gz
web-492433abe865220c227e62cf12f3c93856432585.tar.bz2
web-492433abe865220c227e62cf12f3c93856432585.zip
Initial Portato Website
Diffstat (limited to 'index.py')
-rwxr-xr-xindex.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/index.py b/index.py
new file mode 100755
index 0000000..09a24aa
--- /dev/null
+++ b/index.py
@@ -0,0 +1,69 @@
+#!/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__))
+
+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')
+
+ def render (self, tpl):
+ print tpl
+ try:
+ t = self.get_tpl(tpl)
+ except mako.exceptions.TopLevelLookupException, e:
+ raise web.webapi.notfound(e)
+
+ return partial(t.render, w = web, h = helper)
+
+ __call__ = render
+
+ def get_tpl (self, tpl):
+ return self.lookup.get_template(self.get_tpl_name(tpl))
+
+ def get_tpl_name (self, tpl):
+ if not tpl.endswith(".mako"):
+ tpl = tpl+".mako"
+
+ return os.path.join("pages", tpl)
+
+urls = ("/(.*)", "Handler")
+app = web.application(urls, globals())
+
+render = Renderer()
+
+class Handler:
+ def GET(self, name = '/'):
+ print "Test"
+ if not name or name == '/': name = 'index'
+ return render(name)(menulist = self.generate_menu_list())
+
+ def generate_menu_list (self):
+ menulist = []
+ with open(appdir("templates", "menu.lst")) as menu:
+ for entry in menu:
+ entry = entry.strip()
+ menulist.append((entry, render.get_tpl(entry).uri))
+
+ return menulist
+
+
+# web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
+if __name__ == "__main__":
+ app.run()