improved upload logic, thanks Marin

This commit is contained in:
mdipierro
2012-08-03 09:02:38 -05:00
parent 8a7a723289
commit 57447cb0cf
2 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-08-03 09:01:00) dev Version 2.00.0 (2012-08-03 09:02:35) dev
+11 -6
View File
@@ -1243,14 +1243,19 @@ class SQLFORM(FORM):
else: else:
fields[fieldname] = '' fields[fieldname] = ''
self.vars[fieldname] = fields[fieldname] self.vars[fieldname] = fields[fieldname]
if not f: continue if not f:
if hasattr(f, 'file'): continue
else:
f = os.path.join(current.request.folder,
os.path.normpath(f))
source_file = open(f, 'rb')
original_filename = os.path.split(f)[1]
elif hasattr(f, 'file'):
(source_file, original_filename) = (f.file, f.filename) (source_file, original_filename) = (f.file, f.filename)
elif isinstance(f, (str, unicode)): elif isinstance(f, (str, unicode)):
f = os.path.join(current.request.folder, ### do not know why this happens, it should not
os.path.normpath(f)) (source_file, original_filename) = \
source_file = open(f, 'rb') (cStringIO.StringIO(f), 'file.txt')
original_filename = os.path.split(f)[1]
newfilename = field.store(source_file, original_filename, newfilename = field.store(source_file, original_filename,
field.uploadfolder) field.uploadfolder)
# this line is for backward compatibility only # this line is for backward compatibility only