changeset 15:1ee374416987

handle more gracefully when no file is uploaded
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 12 Jul 2011 09:18:29 -0700
parents 916d45d4f921
children 657e8df14187
files uploader/handlers.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/uploader/handlers.py	Tue Jul 12 09:08:18 2011 -0700
+++ b/uploader/handlers.py	Tue Jul 12 09:18:29 2011 -0700
@@ -53,7 +53,10 @@
 
     def __call__(self):
         fin = self.request.POST['file']
-        _path = fin.filename.replace('..', '_')
+        try:
+            _path = fin.filename.replace('..', '_')
+        except AttributeError: # no file uploaded
+            return self.redirect(self.link('/'))
         _path = _path.replace(os.path.sep, '_')
         _path = os.path.join(self.app.directory, _path)
         self.write(fin, _path)