From 9764086ee9cc10ad1fe7b7cc6f2be82145f843e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 7 Apr 2010 02:00:49 +0200 Subject: Implemented redirecting --- controller.py | 19 +++++++++++++++++++ index.py | 1 + redirects | 2 ++ templates/menu.mako | 5 +++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 redirects diff --git a/controller.py b/controller.py index e694148..7de70f1 100644 --- a/controller.py +++ b/controller.py @@ -1,3 +1,5 @@ +from __future__ import with_statement + import web from renderer import render @@ -9,6 +11,23 @@ class Page: if not name or name == '/': name = 'index' return render(name) +class Redirect: + """ + Redirecting to another page. + """ + + redirects = {} + with open("redirects") as f: + for line in f: + name, url = line.split() + redirects[name.strip()] = url.strip() + + def GET(self, name): + if name not in self.redirects: + raise web.TempRedirect("/") + else: + raise web.Redirect(self.redirects[name], absolute = True) + def FourOhFour(page): """ 404 error page. diff --git a/index.py b/index.py index 74e3e3a..5db7b25 100755 --- a/index.py +++ b/index.py @@ -7,6 +7,7 @@ import controller # URL Mappings # urls = ( + "/r/(.*)", "controller.Redirect", "/(.*)", "controller.Page" ) diff --git a/redirects b/redirects new file mode 100644 index 0000000..b429db2 --- /dev/null +++ b/redirects @@ -0,0 +1,2 @@ +bugs https://bugs.launchpad.net/portato +blog http://necoro.wordpress.com diff --git a/templates/menu.mako b/templates/menu.mako index cf9923e..d74a144 100644 --- a/templates/menu.mako +++ b/templates/menu.mako @@ -2,8 +2,9 @@ menu = [ ("/index", "Portato"), ("/download", "Download"), - ("/development", "Development"), ("/translating", "Translating"), - ("http://necoro.wordpress.com", "Blog") + ("/development", "Development"), + ("/r/bugs", "Bugs"), + ("/r/blog", "Blog") ] %> -- cgit v1.2.3