Opened 15 years ago

Closed 9 years ago

#7808 closed New feature (fixed)

Form Preview does not work with file uploads

Reported by: ian_brasil Owned by: nobody
Component: contrib.formtools Version: dev
Severity: Normal Keywords: FormPreview
Cc: Evstifeev Roman Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Gabriel Hurley)

There seems to be no way to bind a form to a Form Preview (using request.FILES)...
i tried ignoring the specific warning not to override in and tried to override the preview_post() method but this did not work.

Additionally this is not documented on

Change History (11)

comment:1 Changed 15 years ago by Eric Holscher

milestone: 1.0
Triage Stage: UnreviewedDesign decision needed

comment:2 Changed 15 years ago by oyvind

Resolution: wontfix
Status: newclosed

You can't preview files since you can't pass on filefields as a hidden field or fill in filefields in any browser. Filefields will always have to be filled again.

I would not consider this a bug, just something out of scope for formpreview.

comment:3 Changed 14 years ago by anonymous

Resolution: wontfix
Status: closedreopened

This should be mentioned in the FormPreview documentation.

comment:4 Changed 14 years ago by Adam Nelson

Component: UncategorizedDocumentation
milestone: 1.0

Moving out of version milestone:1.0 for triage based on the anonymous comment.

comment:5 Changed 13 years ago by Gabriel Hurley

Description: modified (diff)
Triage Stage: Design decision neededAccepted

My this is an old ticket. I had to update the link to the docs in the ticket description, it was that old.

Anyhow, It seems like a reasonable admonition to add to the Form Preview docs as suggested by anonymous.

comment:6 Changed 13 years ago by ijstokes

Component: Documentationdjango.contrib.formtools
Keywords: FormPreview added
Needs documentation: set

This is not an impossible mission, having FormPreview support files. I made some reasonable progress in about an hour, but it would probably be 1-3 days to get something really working. Below are my notes on how this could be done. I'm going to try and move this to django.contrib.formtools, although a Documentation update would be appreciated -- I wasted several hours reading through FormPreview and trying to get it setup before I realized this wasn't supported, and then put in the extra time to see if I could make it work. Just saying somewhere "This currently doesn't work for Forms with FileFields" would be great.


I've spent about an hour on this and realized that it isn't an easy fix, so I'll have to leave it. FormPreview doesn't support forms with files attached. Search for FormPreview in the django-users list and you'll see more of my comments on this. The couple of things I had to do to get part way to making this work:

  1. Need hashing algorithm to skip FileFields. I did this by adding a class attribute "has_exclude" to the ModelForm and then when looping through the form members I added:

exclude = getattr(form,'hash_exclude', [])
for bp in form:

if in exclude:


In fact, this should be more sophisticated. It should include the *filename* in the hash, but not the file itself. This way the filename forms part of the hash which can be used to recover the "temporary" uploaded file location from the preview stage, and place it into the correct final location. If it isn't part of the hash then the selected file could be manipulated.

  1. Default FormPreview templates need to include enctype="multipart/form-data" attribute on the <form> element.
  1. Need to test form.is_multipart() to see if form should be constructed by:

f = form(request.POST, auto_id=...)


f = form(request.POST, request.FILES, auto_id=...)

  1. And now the tricky bit I didn't get to: how to handle uploaded forms. My suggestion would be to place these in a temporary holding location using a directory taken from the hash. The preview stage would then show the results of any file upload validation (since the files would be submitted with the original submit), and if they are OK, just include the filename. If they are not OK, then the form returns to the original submission page with the errors displayed. If the user confirms everything is alright then the second stage submit sends some hidden field which is associated with the original upload file field and this is used to fetch the originally uploaded file from the hash location and then move it to the final location.

Anyway, that is just the general idea. Maybe there is an easier/better way to do this.

If file uploads aren't OK for FormPreview, then the documentation should reflect this so people don't spend time trying it out only to realize this kind of complicated and fancy handling isn't yet in place.


comment:7 Changed 13 years ago by ijstokes

Another quick point on what would need to be done in the event of a "partial" submitted form where the file is uploaded but then the form isn't finalized/saved/second-stage-submitted. It would be necessary to clean up these old files. My best idea of how to do this would be to run some kind of "tmpwatch" on the temporary parent directory with a 1-48 hour time limit. This would build it into the operation of the system. Otherwise the developer would need to actually include a tmpwatch cronjob or similar to clean "abandoned" files and directories.

comment:8 Changed 13 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:9 Changed 12 years ago by Evstifeev Roman

Cc: Evstifeev Roman added
Easy pickings: unset
UI/UX: unset

comment:10 Changed 11 years ago by Aymeric Augustin

Status: reopenednew

comment:11 Changed 9 years ago by Greg Chapple

Resolution: fixed
Status: newclosed

formtools has been extracted into its own repository (​​​​ Because of this, the issue tracking for this package has been moved to GitHub issues. I'm going to close this ticket, but I've created a GitHub issue to replace it where the conversation can continue: ​​​​ Thanks!

Note: See TracTickets for help on using tickets.
Back to Top