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