Closed ShaheedHaque closed 2 years ago
Here is a prototypical fix. Change https://github.com/jazzband/django-formtools/blob/3b161670549503ae4ed81f9e0a43f2d12fc73e41/formtools/wizard/views.py#L297 to look something like this:
#
# The files storage is sticky w.r.t. optional files.
#
for file in list(self.storage.current_step_files or []):
if file not in form.files:
#
# Remove the previously selected file.
#
file = self.storage.data[self.storage.step_files_key][self.steps.current].pop(file)
self.storage.file_storage.delete(file['tmp_name'])
self.storage.set_step_files(self.steps.current, self.process_step_files(form))
Obsoleted in favour of #207.
Let say you have a with steps Form1 and Form2, where Form1 has a file input, which is optional. If the user takes the following actions:
x.txt
.At this point, the expected behaviour is that:
x.txt
.However, what actually happens is that the code in https://github.com/jazzband/django-formtools/blob/3b161670549503ae4ed81f9e0a43f2d12fc73e41/formtools/wizard/storage/base.py#L105 can only add selected files, and does not remove deselected files.