Django

Code

Ticket #6893 (closed: fixed)

Opened 8 months ago

Last modified 3 months ago

FormWizard does not set the step value correctly

Reported by: siddhi Assigned to: anonymous
Milestone: 1.0 Component: django.contrib.formtools
Version: SVN Keywords: form wizard formtools contrib
Cc: join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de, philipp@igowo.de, rokclimb15@gmail.com, bthomas@ncircle.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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:

  1. The call to get_template uses the step that is passed as a parameter (and has the correct value) instead of using self.step
  2. 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

form_wizard_patch.diff (3.4 kB) - added by siddhi on 03/26/08 05:27:41.
Patch for the code and test cases for this bug
form_wizard_patch_2.diff (3.3 kB) - added by wamberg on 08/01/08 14:02:14.
Updated patch to r8172

Change History

03/26/08 05:27:41 changed by siddhi

  • attachment form_wizard_patch.diff added.

Patch for the code and test cases for this bug

04/18/08 11:17:12 changed by anonymous

  • cc set to join.together@gmail.com.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

05/02/08 09:11:52 changed by trbs

  • cc changed from join.together@gmail.com to join.together@gmail.com, v.oostveen@gmail.com.

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:

  1. This should only be applied once ! (thus not per FormWizard? (sub)class definition)
  2. 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.

05/06/08 05:56:39 changed by anonymous

  • cc changed from join.together@gmail.com, v.oostveen@gmail.com to join.together@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net.

06/14/08 06:42:30 changed by telenieko

  • stage changed from Unreviewed to Accepted.

07/02/08 02:09:36 changed by dan90

  • cc changed from join.together@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net to join.together@gmail.com, dan90, v.oostveen@gmail.com, adam@sitedesign.net.

07/02/08 02:18:20 changed by dan90

  • cc changed from join.together@gmail.com, dan90, v.oostveen@gmail.com, adam@sitedesign.net to join.together@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net.

07/07/08 14:39:35 changed by anonymous

  • milestone set to 1.0.

Since this is a bug, I'm putting it in 1.0

07/15/08 17:10:31 changed by Michael P. Jung

  • cc changed from join.together@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net to join.together@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de.

07/21/08 05:15:50 changed by anonymous

  • cc changed from join.together@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de to join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de.

07/29/08 15:11:19 changed by philwo

  • cc changed from join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de to join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de, philipp@igowo.de.

08/01/08 14:02:14 changed by wamberg

  • attachment form_wizard_patch_2.diff added.

Updated patch to r8172

08/03/08 18:27:27 changed by kmtracey

Closed #8099 as a dup.

08/08/08 10:45:19 changed by mcroydon

  • owner changed from nobody to mcroydon.
  • status changed from new to assigned.

08/08/08 13:01:01 changed by mcroydon

  • owner changed from mcroydon to nobody.
  • status changed from assigned to new.

Tests confirm original bug and pass after the fix is applied.

08/11/08 17:32:42 changed by anonymous

  • cc changed from join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de, philipp@igowo.de to join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de, philipp@igowo.de, rokclimb15@gmail.com.

08/18/08 16:19:19 changed by bthomas

  • cc changed from join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de, philipp@igowo.de, rokclimb15@gmail.com to join.together@gmail.com, newijk@gmail.com, v.oostveen@gmail.com, adam@sitedesign.net, mpjung@terreon.de, philipp@igowo.de, rokclimb15@gmail.com, bthomas@ncircle.com.

08/20/08 14:39:22 changed by anonymous

  • owner changed from nobody to anonymous.
  • status changed from new to assigned.

08/26/08 16:33:56 changed by jacob

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [8603]) Fixed #6893: FormWizard now properly updates its step value. Thanks, siddhi and wamberg.


Add/Change #6893 (FormWizard does not set the step value correctly)




Change Properties
Action