# HG changeset patch # User Jeff Hammel # Date 1283918446 25200 # Node ID 2464e2051b78ecafd57347f65752c3a6945d3060 # Parent 4c83f7715993c077d914268c9a9812e645d1fc5f [mq]: index diff -r 4c83f7715993 -r 2464e2051b78 simplewiki/dispatcher.py --- a/simplewiki/dispatcher.py Tue Sep 07 18:11:04 2010 -0700 +++ b/simplewiki/dispatcher.py Tue Sep 07 21:00:46 2010 -0700 @@ -5,7 +5,7 @@ import os -from handlers import GenshiRenderer +from handlers import GenshiRenderer, Index from genshi.template import TemplateLoader from paste.fileapp import FileApp @@ -30,7 +30,7 @@ assert self.directory and os.path.exists(self.directory), "Must specify an existing directory" # request handlers - self.handlers = [ GenshiRenderer ] + self.handlers = [ GenshiRenderer, Index ] # template loader self.template_dirs = self.template_dirs.split() diff -r 4c83f7715993 -r 2464e2051b78 simplewiki/handlers.py --- a/simplewiki/handlers.py Tue Sep 07 18:11:04 2010 -0700 +++ b/simplewiki/handlers.py Tue Sep 07 21:00:46 2010 -0700 @@ -84,8 +84,35 @@ return getattr(self, self.request.method.title())() def Get(self): - # needs to have self.template set template = self.app.loader.load(self.template) return Response(content_type='text/html', body=template.generate(**self.data).render('html')) + +class Index(Handler): + + template = 'index.html' + + def __init__(self, app, request): + Handler.__init__(self, app, request) + self.directory = os.path.join(app.directory, *request.environ['path']) + if not os.path.isdir(self.directory): + raise HandlerMatchException + path = request.environ['path'] + files = [] + files = os.listdir(self.directory) + self.data = { 'request': request, + 'link': self.link, + 'directory': '/' + '/'.join(path), + 'files': files } + + def __call__(self): + return getattr(self, self.request.method.title())() + + def Get(self): + if not self.request.path_info.endswith('/'): + self.redirect(self.request.path_info + '/') + template = self.app.loader.load(self.template) + return Response(content_type='text/html', + body=template.generate(**self.data).render('html')) + diff -r 4c83f7715993 -r 2464e2051b78 simplewiki/templates/index.html --- a/simplewiki/templates/index.html Tue Sep 07 18:11:04 2010 -0700 +++ b/simplewiki/templates/index.html Tue Sep 07 21:00:46 2010 -0700 @@ -5,18 +5,12 @@ xmlns:py="http://genshi.edgewall.org/" xmlns:xi="http://www.w3.org/2001/XInclude"> -Hello world - - +${directory} - -Hello ${name}! + diff -r 4c83f7715993 -r 2464e2051b78 simplewiki/templates/navigation.html --- a/simplewiki/templates/navigation.html Tue Sep 07 18:11:04 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ - - - - - - -