changeset 13:b8c636b0b567

make work for non pastescript frameworks
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 05 Jul 2011 23:37:52 -0700
parents f60ad139acc1
children 916d45d4f921
files setup.py uploader/handlers.py
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.2.3"
+version = "0.2.4"
 
 setup(name='uploader',
       version=version,
       description="a file uploader app",
       long_description="",
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Ethan Jucovy',
       author_email='',
--- a/uploader/handlers.py
+++ b/uploader/handlers.py
@@ -15,31 +15,35 @@ class Handler(object):
         if permanant:
             application_url = [ self.request.application_url ]
         else:
             application_url = [ self.application_path ]
         path = application_url + path
         return '/'.join(path)
 
     def redirect(self, location):
-        raise exc.HTTPSeeOther(location=location)
+        return exc.HTTPSeeOther(location=location)
 
 class Get(Handler):
 
-    form = """<html><body><form name="upload_form" method="post" enctype="multipart/form-data">
+    form = """<form name="upload_form" method="post" enctype="multipart/form-data">
 <input type="file" name="file"/><input type="submit" value="upload"/></form></body></html>"""
 
     @classmethod
     def match(cls, app, request):
         if app.query_string and (app.query_string not in request.GET):
             return False
         return request.method == 'GET'
 
     def __call__(self):
-        return Response(content_type='text/html', body=self.form)
+        form = "<html><body>"
+        if 'uploaded' in self.request.GET:
+            form += '<div>%s uploaded successfully</div>' % self.request.GET['uploaded']
+        form += self.form + '</body></html>'
+        return Response(content_type='text/html', body=form)
 
 class Post(Handler):
 
     @classmethod
     def match(cls, app, request):
         return request.method == 'POST'
 
     def write(self, fin, path):
@@ -48,17 +52,17 @@ class Post(Handler):
         fout = file(path, 'w')
         fout.write(fin.file.read())
         fout.close()
 
     def __call__(self):
         fin = self.request.POST['file']
         _path = os.path.join(self.app.directory, fin.filename)
         self.write(fin, _path)
-        self.redirect(self.link('/'))
+        return self.redirect(self.link('/?uploaded=' + fin.filename))
 
 def path(directory, request):
     if os.sep == '/':
         return os.path.join(directory, request.path_info.strip('/'))
     return os.path.join(directory, *request.path_info.strip('/').split('/'))
 
 class SubpathGet(Get):
     
@@ -80,10 +84,10 @@ class SubpathPost(Post):
         if os.path.exists(_path) and os.path.isdir(_path):
             return True
 
     def __call__(self):
         fin = self.request.POST['file']
         _path = path(self.app.directory, self.request)
         _path = os.path.join(_path, fin.filename)
         self.write(fin, _path)
-        self.redirect(self.link(self.request.path_info))
+        return self.redirect(self.link(self.request.path_info))