Handling temporary file storage with WizardView
I'm working on a WizardView (django.contrib.formtools) and have a step
that handles a file upload, so I'm setting the file_storage attribute
as required. I'd like the file storage to be a securely created
temporary directory under /tmp so I'm trying to set it to an instance
of tempfile.mkdtemp as below, but I'm stumping myself:
class FileSubmissionWizardView(SessionWizardView):
"Form wizard implementation to handle uploaded samples"
# XXX required. Also, need to take care of removing dir/file in the end.
file_storage = FileSystemStorage(location=mkdtemp(prefix='avsubmit_'))
def done(self, form_list, **kwargs):
# do_something_with_the_form_data(form_list)
# Remove temp upload directory. Eh?
shutil.rmtree(self.file_storage.location)
# Set a message, do a log
return redirect('avsubmit_index')
def process_step_files(self, form):
# do something like set storage extra data
return self.get_form_step_files(form)
My fu is weak, so I'm not certain the right approach here.
file_storage is a class attribute (right?), so I'm not sure this meets
my envisioned goal of having a new temporary directory created for
each uploaded file which I can then delete when finished. Would like
this workflow:
1. User uploads file
2. View invoked to process form, creates _new_ temporary directory for
FileSystemStorage and writes uploaded file to dir. Variable is
populated containing path from mkdtemp() to delete later
3. View processes form
4. View calls shutil.rmtree to delete temporary directory and file
5. View complete
How far off of target am I? Is there a good way to do the above file
resource management using WizardView?
--
Darren Spruell
phatbuckett@gmail.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home