FormWizard sanity check on step number performed before dynamic steps can be inserted
|Reported by:||Owned by:||esper256|
|Cc:||michal.modzelewski@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
If you are making a FormWizard to have dynamically created steps, where the number of steps depends on the form input of the previous steps, you run into a problem with the sanity check inside FormWizard's
# Sanity check. if current_step >= self.num_steps(): raise Http404('Step %s does not exist' % current_step) # For each previous step, verify the hash and process. # TODO: Move "hash_%d" to a method to make it configurable. for i in range(current_step): form = self.get_form(i, request.POST) if request.POST.get("hash_%d" % i, '') != self.security_hash(request, form): return self.render_hash_failure(request, i) self.process_step(request, form, i)
Your cleaned_data to determine if you need to add more steps isn't available until process_step is called on the earlier steps. However it will never get that far because the current step will be over the number of steps the FormWizard was initially constructed with (in the urls.py for example).
Currently I have worked around this in my code by constructing FormWizard with enough dummy steps that are removed and replaced with real ones just so the formcount is always greater than the dynamic count will ever be in the very beginning.
My proposed solution would be to do a sanity check each iteration of the forloop ensuring that there's at least enough forms to process the next one.
Change History (14)
comment:1 Changed 7 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|
comment:5 Changed 6 years ago by
|Version:||1.1 → SVN|
comment:6 Changed 5 years ago by