Fix handling of 'filename' field when making new batch

This commit is contained in:
Lance Edgar 2018-05-22 15:31:31 -05:00
parent b0e8f7d985
commit ecf7acc800

View file

@ -312,7 +312,7 @@ class BatchMasterView(MasterView):
f.remove_field('complete')
def save_create_form(self, form):
uploads = self.normalize_uploads(form, skip=['filename'])
uploads = self.normalize_uploads(form)
self.before_create(form)
session = self.Session()
@ -327,18 +327,10 @@ class BatchMasterView(MasterView):
# obtain kwargs for making batch via handler, below
kwargs = self.get_batch_kwargs(batch)
# TODO: this needs work yet surely...
if 'filename' in form.schema:
filedict = kwargs.pop('filename', None)
filepath = None
if filedict:
# TODO: this needs work yet surely...why is this an issue?
# treat 'filename' field specially, for some reason it can be a filedict?
if 'filename' in kwargs and not isinstance(kwargs['filename'], six.string_types):
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