comparison 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
comparison
equal deleted inserted replaced
2:2464e2051b78 3:56ab6b90cd1a
114 self.redirect(self.request.path_info + '/') 114 self.redirect(self.request.path_info + '/')
115 template = self.app.loader.load(self.template) 115 template = self.app.loader.load(self.template)
116 return Response(content_type='text/html', 116 return Response(content_type='text/html',
117 body=template.generate(**self.data).render('html')) 117 body=template.generate(**self.data).render('html'))
118 118
119 class Post(Handler):
120 methods = set(['POST']) # methods to listen to
121
122 def __init__(self, app, request):
123 Handler.__init__(self, app, request)
124 if 'file' not in request.POST:
125 raise HandlerMatchException
126 self.file = self.request.POST['file']
127 if not getattr(self.file, 'filename', None):
128 raise HandlerMatchException
129 self.location = request.path_info.rstrip('/')
130 path = os.path.join(self.app.directory, *self.request.environ['path'])
131 if os.path.isdir(path):
132 self.directory = path
133 self.filename = os.path.join(self.directory, self.file.filename)
134 self.location += '/' + self.file.filename
135 else:
136 self.directory = os.path.dirname(path)
137 self.filename = path
138
139 f = file(self.filename, 'wb')
140 f.write(self.file.file.read())
141 f.close()
142
143 def __call__(self):
144 self.redirect(self.location)