Ticket #18000: wizard_save_goto_step.diff

File wizard_save_goto_step.diff, 2.8 KB (added by creecode, 13 years ago)
  • django/contrib/formtools/wizard/views.py

     
    246246
    247247        The wizard will render either the current step (if form validation
    248248        wasn't successful), the next step (if the current step was stored
    249         successful) or the done view (if no more steps are available)
     249        successfully) or the done view (if no more steps are available)
    250250        """
    251251        # Look for a wizard_goto_step element in the posted data which
    252252        # contains a valid step name. If one was found, render the requested
    253253        # form. (This makes stepping back a lot easier).
    254         wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
    255         if wizard_goto_step and wizard_goto_step in self.get_form_list():
    256             self.storage.current_step = wizard_goto_step
    257             form = self.get_form(
    258                 data=self.storage.get_step_data(self.steps.current),
    259                 files=self.storage.get_step_files(self.steps.current))
    260             return self.render(form)
     254        wizard_cancel_step_goto = self.request.POST.get(
     255            'wizard_cancel_step_goto', None)
     256        if wizard_cancel_step_goto and wizard_cancel_step_goto in \
     257            self.get_form_list():
     258            return self.render_step(wizard_cancel_step_goto)
    261259
    262260        # Check if form was refreshed
    263261        management_form = ManagementForm(self.request.POST, prefix=self.prefix)
     
    280278            self.storage.set_step_data(self.steps.current, self.process_step(form))
    281279            self.storage.set_step_files(self.steps.current, self.process_step_files(form))
    282280
     281            # check if this is a goto step
     282            wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
     283            if wizard_goto_step and wizard_goto_step in self.get_form_list():
     284                return self.render_step(wizard_goto_step)
     285
    283286            # check if the current step is the last step
    284287            if self.steps.current == self.steps.last:
    285288                # no more steps, render done view
     
    553556        raise NotImplementedError("Your %s class has not defined a done() "
    554557            "method, which is required." % self.__class__.__name__)
    555558
     559    def render_step ( self, step ):
     560        """
     561        This method is used to render a given step. `step` contains the step-name.
     562        """
     563        self.storage.current_step = step
     564        form = self.get_form(
     565            data=self.storage.get_step_data(self.steps.current),
     566            files=self.storage.get_step_files(self.steps.current))
     567        return self.render(form)
    556568
     569
    557570class SessionWizardView(WizardView):
    558571    """
    559572    A WizardView with pre-configured SessionStorage backend.
Back to Top