#6893 closed (fixed)
FormWizard does not set the step value correctly
Reported by: | siddhi | Owned by: | anonymous |
---|---|---|---|
Component: | contrib.formtools | Version: | dev |
Severity: | Keywords: | form wizard formtools contrib | |
Cc: | join.together@…, newijk@…, v.oostveen@…, adam@…, mpjung@…, philipp@…, rokclimb15@…, bthomas@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The FormWizard class in django.contrib.formtools.wizard has a method called get_template which can be overridden to return a template for each step of the form submission process. This get_template method gets the step value as a parameter. However, no matter what step of the form processing we are in, this parameter is always 0.
The step value everywhere else is either computed dynamically or passed as a parameter. Only the get_template call uses self.step which is initialised to 0 and then never set again as we move through the steps.
The patch contains two fixes:
- The call to get_template uses the step that is passed as a parameter (and has the correct value) instead of using self.step
- self.step is updated at the end of processing
The patch also contains two test cases to check this. One of the tests should fail with the old code. Both tests should pass with the patched code.
As an aside, self.step is now used only in the repr method, so maybe it can be removed from there and then removed entirely from the FormWizard class?
Attachments (2)
Change History (22)
by , 17 years ago
Attachment: | form_wizard_patch.diff added |
---|
comment:1 by , 17 years ago
Cc: | added |
---|
comment:2 by , 17 years ago
Cc: | added |
---|
Also hit this problem today and the patch looks fine to me.
At this moment, I've written a decorator for the formwizard.render_template method to inject the assignment of the self.step variable.
The code below is just a HACK and is by no means a permanent solution.
## Hack in FormWizard until django ticket #6893 is solved def formwizard_render_template_decorator(func): def inject_assign_step(klass, request, form, previous_fields, step, *args, **kwargs): klass.step = step return func(klass, request, form, previous_fields, step, *args, **kwargs) return inject_assign_step FormWizard.render_template = formwizard_render_template_decorator(FormWizard.render_template)
If you want to use this hack note two important things:
- This should only be applied once ! (thus not per FormWizard (sub)class definition)
- It must be removed after a fix is made !
I've only added this to the comments for people that do not like to patch the django installation there running.
But like said above this does require you to remember to remove it when a solution/patch hits django trunk.
comment:3 by , 17 years ago
Cc: | added |
---|
comment:4 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 16 years ago
Cc: | added |
---|
comment:6 by , 16 years ago
Cc: | removed |
---|
comment:8 by , 16 years ago
Cc: | added |
---|
comment:9 by , 16 years ago
Cc: | added |
---|
comment:10 by , 16 years ago
Cc: | added |
---|
comment:12 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:13 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
Tests confirm original bug and pass after the fix is applied.
comment:14 by , 16 years ago
Cc: | added |
---|
comment:15 by , 16 years ago
Cc: | added |
---|
comment:16 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:17 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:18 by , 16 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:19 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Patch for the code and test cases for this bug