Mercurial > hg > SimpleWiki
diff simplewiki/handlers.py @ 2:2464e2051b78
[mq]: index
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 07 Sep 2010 21:00:46 -0700 |
parents | 4c83f7715993 |
children | 56ab6b90cd1a |
line wrap: on
line diff
--- 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')) +