Opened 12 years ago
Closed 12 years ago
#19285 closed New feature (duplicate)
Allow to redirect user back in Form wizard
Reported by: | azurit | Owned by: | nobody |
---|---|---|---|
Component: | contrib.formtools | Version: | 1.4 |
Severity: | Normal | Keywords: | form wizard formwizard |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I was fighting with problem in allowing to redirect user back when using Form wizard. Here is the use case:
- user1 will choose a login and password in first step, login availability is checked
- user1 is redirected to second step where he needs to fill up other important data for creating his account
- meanwhile, user2 registers and takes login of user1
- finally, we got an error when creating the account for user1. here we need to redirect him to first step and ask him for another login
I wasn't able to find any way how to do this. Finally i was trying to simulate usage of 'Go back' button, which is defined in contrib/formtools/wizard/views.py in WizardView.post() method:
# Look for a wizard_goto_step element in the posted data which # contains a valid step name. If one was found, render the requested # form. (This makes stepping back a lot easier). wizard_goto_step = self.request.POST.get('wizard_goto_step', None) if wizard_goto_step and wizard_goto_step in self.get_form_list(): self.storage.current_step = wizard_goto_step form = self.get_form( data=self.storage.get_step_data(self.steps.current), files=self.storage.get_step_files(self.steps.current)) return self.render(form)
Unfortunately this won't work in final step, becase of resetting the form wizard in the same file at the end of WizardView.render_done() method:
done_response = self.done(final_form_list, * *kwargs) self.storage.reset() return done_response
I altered this method to make it work also in final step like this:
done_response = self.done(final_form_list, **kwargs) if self.steps.current == self.steps.last: self.storage.reset() return done_response
Do you consider this as a usefull patch which can be included in Django? Or can you suggest another correct way how to do this?
Change History (2)
comment:1 by , 12 years ago
Needs documentation: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Actually, marking this as a duplicate of #19189.
I think this may just be a documentation issue. For my money, part of the design contract for the Form Wizard is that once validated, the form will be able to reliably save without error.
In your case, I think this means that you need to 'reserve' the username as part of the validation process -- i.e., when the form validates for user1, it stores a value in temporary storage that would prevent user2 from validating with the same value. You could use something as simple as a cache key, or even a whole temporary table to handle this.
I'm accepting this ticket on the basis that the design contract needs to be better documented, and possibly use cases like yours need to be highlighted as part of that documentation.