Don't process file for new batch unless field is present

This commit is contained in:
Lance Edgar 2018-02-03 14:49:49 -06:00
parent 737b2e578a
commit aded59d7ff

View file

@ -129,16 +129,17 @@ class BatchMasterView3(MasterView3, BatchMasterView2):
kwargs = self.get_batch_kwargs(batch) kwargs = self.get_batch_kwargs(batch)
# TODO: this needs work yet surely... # TODO: this needs work yet surely...
filedict = kwargs.pop('filename', None) if 'filename' in form.schema:
filepath = None filedict = kwargs.pop('filename', None)
if filedict: filepath = None
kwargs['filename'] = '' # null not allowed if filedict:
tempdir = tempfile.mkdtemp() kwargs['filename'] = '' # null not allowed
filepath = os.path.join(tempdir, filedict['filename']) tempdir = tempfile.mkdtemp()
tmpinfo = form.deform_form['filename'].widget.tmpstore.get(filedict['uid']) filepath = os.path.join(tempdir, filedict['filename'])
tmpdata = tmpinfo['fp'].read() tmpinfo = form.deform_form['filename'].widget.tmpstore.get(filedict['uid'])
with open(filepath, 'wb') as f: tmpdata = tmpinfo['fp'].read()
f.write(tmpdata) with open(filepath, 'wb') as f:
f.write(tmpdata)
# TODO: is this still necessary with colander? # TODO: is this still necessary with colander?
# destroy initial batch and re-make using handler # destroy initial batch and re-make using handler
@ -150,10 +151,11 @@ class BatchMasterView3(MasterView3, BatchMasterView2):
# TODO: this needs work yet surely... # TODO: this needs work yet surely...
# if batch has input data file, let handler properly establish that # if batch has input data file, let handler properly establish that
if filedict: if 'filename' in form.schema:
self.handler.set_input_file(batch, filepath) if filedict:
os.remove(filepath) self.handler.set_input_file(batch, filepath)
os.rmdir(tempdir) os.remove(filepath)
os.rmdir(tempdir)
return batch return batch