Ticket #7439: multipart_form_as_last_in_formwizard.diff

File multipart_form_as_last_in_formwizard.diff, 2.6 KB (added by makoste, 5 years ago)

add raise when multipart form is not as last

  • contrib/formtools/wizard.py

     
    4242    def __repr__(self):
    4343        return "step: %d\nform_list: %s\ninitial_data: %s" % (self.step, self.form_list, self.initial)
    4444
    45     def get_form(self, step, data=None):
     45    def get_form(self, step, data=None, files=None):
    4646        "Helper method that returns the Form instance for the given step."
    47         return self.form_list[step](data, prefix=self.prefix_for_step(step), initial=self.initial.get(step, None))
     47        return self.form_list[step](data, files, prefix=self.prefix_for_step(step), initial=self.initial.get(step, None))
    4848
    4949    def num_steps(self):
    5050        "Helper method that returns the number of steps."
     
    7171        # For each previous step, verify the hash and process.
    7272        # TODO: Move "hash_%d" to a method to make it configurable.
    7373        for i in range(current_step):
    74             form = self.get_form(i, request.POST)
     74            form = self.get_form(i, request.POST, request.FILES)
    7575            if request.POST.get("hash_%d" % i, '') != self.security_hash(request, form):
    7676                return self.render_hash_failure(request, i)
    7777            self.process_step(request, form, i)
     
    7979        # Process the current step. If it's valid, go to the next step or call
    8080        # done(), depending on whether any steps remain.
    8181        if request.method == 'POST':
    82             form = self.get_form(current_step, request.POST)
     82            form = self.get_form(current_step, request.POST, request.FILES)
    8383        else:
    8484            form = self.get_form(current_step)
    8585        if form.is_valid():
     
    9090            # time, as a sanity check, and call done().
    9191            num = self.num_steps()
    9292            if next_step == num:
    93                 final_form_list = [self.get_form(i, request.POST) for i in range(num)]
     93                final_form_list = [self.get_form(i, request.POST, request.FILES) for i in range(num)]
    9494
    9595                # Validate all the forms. If any of them fail validation, that
    9696                # must mean the validator relied on some other input, such as
     
    102102
    103103            # Otherwise, move along to the next step.
    104104            else:
     105                if form.is_multipart():
     106                    raise NotImplementedError("Your %s class has not initialized multipart form as last." % self.__class__.__name__)
    105107                form = self.get_form(next_step)
    106108                self.step = current_step = next_step
    107109
Back to Top