django-formtools
django-formtools copied to clipboard
multiple `get_form_initial` calls when `condition_dict` is used
Don't know why, but when I use condition_dict
, the get_form_initial
def is called multiple times.
The above problem is seen when I use wizard.get_cleaned_data_for_step()
in condition def.
Any clues?
@adi- Can you please tell about the file and line number where you find this error
I am implementing as exampled here: https://django-formtools.readthedocs.io/en/latest/wizard.html#formtools.wizard.views.WizardView.condition_dict
When wizard.get_cleaned_data_for_step('0')
is present (not #) in views.py
, get_form_initial
is initiated multiple times. When you rem this line, everything works as expected.
I have also added hooks (simple print
statement) for get_form_kwargs
, get_form_initial
and condition function. I don't see any reason, why those functions are fired multiple times... But only when wizard.get_cleaned_data_for_step
is present in condition function.
I have the same problem..any solution?
Any patch with tests will be welcome!
@GiuseppePegasus : as a workaround I use wizard.storage.data['step_data']
to avoid infinite recursion or to fire wizard's methods too early (get_form()
, get_form_initial()
).
I think the problem is: https://github.com/jazzband/django-formtools/blob/master/formtools/wizard/views.py#L47
This all property is used a lot and recalculates the form_list
using the conditions each time it is invoked. I actually had this problem too locally and found out that Django's debug toolbars way of displaying info nicely caused an excessive amount of all
invocations. Removing the debug toolbar already significantly improved the behaviour.
It might be nice to generate the form_list
once per use of the wizard.