# HG changeset patch # User Jeff Hammel # Date 1283920197 25200 # Node ID 56ab6b90cd1ae3e64a35a00d7b2820f72bddba96 # Parent 2464e2051b78ecafd57347f65752c3a6945d3060 [mq]: post diff -r 2464e2051b78 -r 56ab6b90cd1a example/avatar.jpg Binary file example/avatar.jpg has changed diff -r 2464e2051b78 -r 56ab6b90cd1a simplewiki/dispatcher.py --- a/simplewiki/dispatcher.py Tue Sep 07 21:00:46 2010 -0700 +++ b/simplewiki/dispatcher.py Tue Sep 07 21:29:57 2010 -0700 @@ -5,7 +5,7 @@ import os -from handlers import GenshiRenderer, Index +from handlers import GenshiRenderer, Index, Post 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, Index ] + self.handlers = [ Post, GenshiRenderer, Index ] # template loader self.template_dirs = self.template_dirs.split() diff -r 2464e2051b78 -r 56ab6b90cd1a simplewiki/handlers.py --- 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) diff -r 2464e2051b78 -r 56ab6b90cd1a simplewiki/templates/index.html --- a/simplewiki/templates/index.html Tue Sep 07 21:00:46 2010 -0700 +++ b/simplewiki/templates/index.html Tue Sep 07 21:29:57 2010 -0700 @@ -12,5 +12,11 @@
  • ..
  • ${f}
  • +
    +

    Upload a file:

    + + +
    +