﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20056	get_cleaned_data_for_step & condition_dict in FormWizard	tordox@…	nobody	"I made a FormWizard, exactly like that from the Documentation and I found a problem with ""get_cleaned_data_for_step"" and condition_dict. I don't know this is a Bug in django, or maybe I make a mistake.

Here the Code:

urls.py
{{{
 # ...
 url(r'^wizard/$',
        ContactWizard.as_view(contact_forms, condition_dict={""1"": show_message_form_condition}))
# ...

}}}

forms.py

{{{
from django import forms

class ContactForm1(forms.Form):
    subject = forms.CharField(max_length=100)
    sender = forms.EmailField()
    leave_message = forms.BooleanField(required=False)

class ContactForm2(forms.Form):
    message = forms.CharField(widget=forms.Textarea)
}}}

views.py 


{{{
from django.shortcuts import render_to_response
from django.contrib.formtools.wizard.views import SessionWizardView


def show_message_form_condition(wizard):
    # try to get the cleaned data of step 1
    cleaned_data = wizard.get_cleaned_data_for_step('0') or {}
    # check if the field ``leave_message`` was checked.
    return cleaned_data.get('leave_message', True)


class ContactWizard(SessionWizardView):

    template_name = ""wizard.html""

    def get_form_kwargs(self, step=None):
        print ""get_form_kwargs""
        kwargs = super(ContactWizard, self).get_form_kwargs(step)
        return kwargs

    def done(self, form_list, **kwargs):
        return render_to_response('/', {
            'form_data': [form.cleaned_data for form in form_list],
            })
}}}

You see, the ContactWizard is like that from the documentation.
I just override and put in ""get_form_kwargs"" a print statement.

If I load the page at Firefox, fill out the fields from the first step and click to the next step. This is how the console looks like:


{{{
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
[15/Mar/2013 23:53:19] ""GET /wizard/ HTTP/1.1"" 200 900
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
get_form_kwargs
[15/Mar/2013 23:53:27] ""POST /wizard/ HTTP/1.1"" 200 806

}}}

I know, this is because of ""get_cleaned_data_for_step('0')"" and get_form_list() in formtools.wizard.views but I don't know how I avoid the multiple calls of get_form_list. If there is a query in a ModelForm, for example for a select field, the loop of get_form_kwargs call it multiple times.

I don't know what needs so many get_form_kwargs calls?
I hope someone make a look at this, because I have bad python skills.
And sorry for my bad english :("	Bug	closed	contrib.formtools	1.5	Normal	duplicate			Unreviewed	0	0	0	0	0	0
