From aded59d7ff9d3d6c76704e3338d7e0b1dde3a4a6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 3 Feb 2018 14:49:49 -0600 Subject: [PATCH] Don't process file for new batch unless field is present --- tailbone/views/batch/core3.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tailbone/views/batch/core3.py b/tailbone/views/batch/core3.py index 6f37e648..92dedf26 100644 --- a/tailbone/views/batch/core3.py +++ b/tailbone/views/batch/core3.py @@ -129,16 +129,17 @@ class BatchMasterView3(MasterView3, BatchMasterView2): kwargs = self.get_batch_kwargs(batch) # TODO: this needs work yet surely... - filedict = kwargs.pop('filename', None) - filepath = None - if filedict: - kwargs['filename'] = '' # null not allowed - tempdir = tempfile.mkdtemp() - filepath = os.path.join(tempdir, filedict['filename']) - tmpinfo = form.deform_form['filename'].widget.tmpstore.get(filedict['uid']) - tmpdata = tmpinfo['fp'].read() - with open(filepath, 'wb') as f: - f.write(tmpdata) + if 'filename' in form.schema: + filedict = kwargs.pop('filename', None) + filepath = None + if filedict: + kwargs['filename'] = '' # null not allowed + tempdir = tempfile.mkdtemp() + filepath = os.path.join(tempdir, filedict['filename']) + tmpinfo = form.deform_form['filename'].widget.tmpstore.get(filedict['uid']) + tmpdata = tmpinfo['fp'].read() + with open(filepath, 'wb') as f: + f.write(tmpdata) # TODO: is this still necessary with colander? # destroy initial batch and re-make using handler @@ -150,10 +151,11 @@ class BatchMasterView3(MasterView3, BatchMasterView2): # TODO: this needs work yet surely... # if batch has input data file, let handler properly establish that - if filedict: - self.handler.set_input_file(batch, filepath) - os.remove(filepath) - os.rmdir(tempdir) + if 'filename' in form.schema: + if filedict: + self.handler.set_input_file(batch, filepath) + os.remove(filepath) + os.rmdir(tempdir) return batch