django-formtools
django-formtools copied to clipboard
Easy was to skip step without hacks...
I have something like this:
form_list = [
("select_lang", SelectLanguageForm),
("foo", SecondForm),
]
The first step of the wizard is to select a language and the second step used the language for setup the form. That works fine.
Now, i would like to optional skip the first step, if a url like: "/my_wizard?language=XY" is used.
It seems, that this is not easy doable, isn't it?!?
Haven't tried but something like:
def is_language_selection_needed(wizard):
return not wizard.request.GET.has_key('language')
...
condition__dict = {'select_lang': is_language_selection_needed}
is not working? (It might mess up the next steps though, once the URL changes so you might something else)
Yes, the skip can be done in this way...
The problem is: I i must change code parts if the first form was skipped... The problem is to fill the information to the internal state, so that the code for the second step can work in the same way...
Yeah, I understand... You could probably tweak around with the extra_data
attribute in the storage, by overriding the get
method of WizardView
, BUT you can't really use super()
in this case since the first action done in the inherited get
will be self.storage.reset()
, erasing your data.
You could do that in the condition method but I think it is error-prone (each condition is called at every request at least once to construct the form list, so you need to be extra careful and check you won't alter the session on the next steps). But I find it dirty (those functions should only return boolean, without side effect)
Maybe adding a new call in WizardView.get
, allowing user to do extra stuff on the wizard initialization could be great. I believe I had the same problem months ago, and I ended up doing dirty stuff in the condition dict...
Yes, i currently use also some dirty things to get this working... So i think there should be exist a good way in formtools.