# HG changeset patch # User Jeff Hammel # Date 1283925491 25200 # Node ID b2fbb4f982dacb2ce1c73c52bf23b1740ab5a695 # Parent dd1c4916cbcd743e913015321071a060c98fdc34 [mq]: edit diff -r dd1c4916cbcd -r b2fbb4f982da example/hello.html --- a/example/hello.html Tue Sep 07 22:39:15 2010 -0700 +++ b/example/hello.html Tue Sep 07 22:58:11 2010 -0700 @@ -1,8 +1,8 @@ - - -Hello, world! - - -Hello, world! - - + + +Hello, world! + + +Hello, worldz! + + diff -r dd1c4916cbcd -r b2fbb4f982da simplewiki/dispatcher.py --- a/simplewiki/dispatcher.py Tue Sep 07 22:39:15 2010 -0700 +++ b/simplewiki/dispatcher.py Tue Sep 07 22:58:11 2010 -0700 @@ -5,7 +5,7 @@ import os -from handlers import GenshiRenderer, Index, Post, FileServer +from handlers import GenshiRenderer, Index, Post, FileServer, EditView 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 = [ Post, GenshiRenderer, Index, FileServer ] + self.handlers = [ Post, EditView, GenshiRenderer, Index, FileServer ] # template loader self.template_dirs = self.template_dirs.split() diff -r dd1c4916cbcd -r b2fbb4f982da simplewiki/handlers.py --- a/simplewiki/handlers.py Tue Sep 07 22:39:15 2010 -0700 +++ b/simplewiki/handlers.py Tue Sep 07 22:58:11 2010 -0700 @@ -125,20 +125,24 @@ if 'file' not in request.POST: raise HandlerMatchException self.file = self.request.POST['file'] - if not getattr(self.file, 'filename', None): - raise HandlerMatchException + filename = getattr(self.file, 'filename', '') + if filename: + content = self.file.file.read() + else: + content = self.file + 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 + self.filename = os.path.join(self.directory, filename) + self.location += '/' + filename else: self.directory = os.path.dirname(path) self.filename = path f = file(self.filename, 'wb') - f.write(self.file.file.read()) + f.write(content) f.close() def __call__(self): @@ -156,3 +160,29 @@ def __call__(self): return FileApp(self.file) +class EditView(Handler): + methods = set(['GET']) + template = 'edit.html' + + def __init__(self, app, request): + if 'edit' not in request.GET: + raise HandlerMatchException + + Handler.__init__(self, app, request) + + self.file = os.path.join(self.app.directory, *request.environ['path']) + if not os.path.exists(self.file): + raise HandlerMatchException + self.data = { 'request': request, + 'link': self.link, + 'file': '/' + '/'.join(request.environ['path']), + 'content': file(self.file).read() + } + + def __call__(self): + return getattr(self, self.request.method.title())() + + def Get(self): + template = self.app.loader.load(self.template) + return Response(content_type='text/html', + body=template.generate(**self.data).render('html'))