Mercurial > hg > SimpleWiki
diff simplewiki/handlers.py @ 3:56ab6b90cd1a
[mq]: post
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 07 Sep 2010 21:29:57 -0700 |
parents | 2464e2051b78 |
children | dd1c4916cbcd |
line wrap: on
line diff
--- a/simplewiki/handlers.py Tue Sep 07 21:00:46 2010 -0700 +++ b/simplewiki/handlers.py Tue Sep 07 21:29:57 2010 -0700 @@ -116,3 +116,29 @@ return Response(content_type='text/html', body=template.generate(**self.data).render('html')) +class Post(Handler): + methods = set(['POST']) # methods to listen to + + def __init__(self, app, request): + Handler.__init__(self, app, request) + if 'file' not in request.POST: + raise HandlerMatchException + self.file = self.request.POST['file'] + if not getattr(self.file, 'filename', None): + raise HandlerMatchException + self.location = request.path_info.rstrip('/') + path = os.path.join(self.app.directory, *self.request.environ['path']) + if os.path.isdir(path): + self.directory = path + self.filename = os.path.join(self.directory, self.file.filename) + self.location += '/' + self.file.filename + else: + self.directory = os.path.dirname(path) + self.filename = path + + f = file(self.filename, 'wb') + f.write(self.file.file.read()) + f.close() + + def __call__(self): + self.redirect(self.location)