Code

Opened 6 years ago

Closed 3 years ago

#7439 closed New feature (fixed)

FormWizard don't process multipart forms

Reported by: Damian Świstowski <damian@…> Owned by: nobody
Component: contrib.formtools Version: master
Severity: Normal Keywords: wizard
Cc: stryderjzw@…, philipp.bosch@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX:

Description

get_form method creating form only with request.POST parameter, adding request.FILES resolves problem.

Attachments (2)

added_files_to_get_form_method.diff (2.2 KB) - added by Damian Świstowski <damian@…> 6 years ago.
multipart_form_as_last_in_formwizard.diff (2.6 KB) - added by makoste 4 years ago.
add raise when multipart form is not as last

Download all attachments as: .zip

Change History (16)

Changed 6 years ago by Damian Świstowski <damian@…>

comment:1 Changed 6 years ago by programmerq

  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by mcroydon

  • milestone set to 1.0
  • Owner changed from nobody to mcroydon
  • Status changed from new to assigned

comment:3 Changed 6 years ago by mcroydon

  • Owner changed from mcroydon to nobody
  • Status changed from assigned to new

This patch still applies cleanly.

comment:4 Changed 6 years ago by jacob

  • milestone changed from 1.0 to post-1.0
  • Needs tests set
  • Patch needs improvement set

This is a borderline feature addition, and without tests I'm reluctant to check it in this late. I'm going to push post-1.0; if someone can get a (passing) test written by 8/30, pop this back to the 1.0 milestone and I'll check it in.

comment:5 Changed 5 years ago by stryderjzw

  • Cc stryderjzw@… added

comment:6 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:7 Changed 5 years ago by telenieko

This thing should be documented somehow, documentation reads (now):
"""Important limitation: Because the wizard uses HTML hidden fields to store data between pages, you may not include a FileField in any form except the last one."""

I'd say you cannot include a FileField on *any* form neither the last one, as request.FILES never gets passed around. Until this gets fixed we should tell people that their files will be left in limbo! ;)

(Or I did something really bad and I should really be getting my files on the last form! :)

comment:8 Changed 4 years ago by anonymous

  • Cc philipp.bosch@… added

Changed 4 years ago by makoste

add raise when multipart form is not as last

comment:9 Changed 4 years ago by anonymous

Perhaps I did something wrong, but when I tried implementing the patches (by overriding get_form and call in my FormWizard subclass), I get a "Please upload a valid image. The file you uploaded was either not an image or a corrupted image." error every time with an ImageField.

comment:10 Changed 3 years ago by russellm

  • Keywords wizard added

comment:11 Changed 3 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:12 Changed 3 years ago by oluwaseun

  • Easy pickings unset

Now I just did a hack and maybe this might help somebody

Line 117: f = self.get_form(i, request.POST)
Change to: f = self.get_form(i, request.POST, request.FILES)

Line 131: form = self.get_form(current_step, request.POST)
Change to: form = self.get_form(current_step, request.POST, request.FILES)

Line 46 of the get_form method: def get_form(self, step, data=None)
Change the signature to: def get_form(self, step, post=None, files=None):

Then you should be fine.But there's a caveat though, your file must be on the last form also you cannot have two select options on the same page.
I don't know why that is a problem. Still checking whats is wrong. Also I would love to know if anyone has been able to make the form go back i.e. using a previous and next button. I'm working on that now though but if someone has fixed that. Would be glad to know.
I hope this helps somebody.

comment:13 Changed 3 years ago by steph

See #9200. The features requested here will be solved with the patch in #9200.

comment:14 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

Superseded by #9200.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.