#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)
Changed 15 years ago by
Attachment: | form_wizard_patch.diff added |
---|
comment:1 Changed 15 years ago by
Cc: | join.together@… added |
---|
comment:2 Changed 15 years ago by
Cc: | v.oostveen@… 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 Changed 15 years ago by
Cc: | adam@… added |
---|
comment:4 Changed 15 years ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 Changed 15 years ago by
Cc: | dan added |
---|
comment:6 Changed 15 years ago by
Cc: | dan removed |
---|
comment:8 Changed 15 years ago by
Cc: | mpjung@… added |
---|
comment:9 Changed 15 years ago by
Cc: | newijk@… added |
---|
comment:10 Changed 15 years ago by
Cc: | philipp@… added |
---|
comment:12 Changed 15 years ago by
Owner: | changed from nobody to mcroydon |
---|---|
Status: | new → assigned |
comment:13 Changed 14 years ago by
Owner: | changed from mcroydon to nobody |
---|---|
Status: | assigned → new |
Tests confirm original bug and pass after the fix is applied.
comment:14 Changed 14 years ago by
Cc: | rokclimb15@… added |
---|
comment:15 Changed 14 years ago by
Cc: | bthomas@… added |
---|
comment:16 Changed 14 years ago by
Owner: | changed from nobody to anonymous |
---|---|
Status: | new → assigned |
comment:17 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:18 Changed 14 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:19 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Patch for the code and test cases for this bug