Opened 2 years ago

Closed 23 months ago

#20056 closed Bug (duplicate)

get_cleaned_data_for_step & condition_dict in FormWizard

Reported by: tordox@… Owned by: nobody
Component: contrib.formtools Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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 :(

Change History (7)

comment:1 Changed 2 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

why is this still unreviewed?

comment:2 Changed 2 years ago by tundebabzy

  • Resolution set to fixed
  • Status changed from new to closed

Hi. Have a look at ticket:18803#comment:1 which is similar to yours. The conclusion is that this behaviour is not a bug.

comment:3 Changed 2 years ago by tundebabzy

  • Resolution changed from fixed to invalid

comment:4 follow-up: Changed 2 years ago by anonymous

  • Type changed from Uncategorized to Bug

This is definitiv a bug. The condition_dict is not usable with this.

comment:5 in reply to: ↑ 4 Changed 2 years ago by robert

  • Version changed from 1.4 to 1.5

I agree this should be solved.

My wizard has two simple conditions for three different steps.
Basically ‘user is professional or private’ set in step two.
Handling step 3 queries the database twenty times for a —already validated— user.

form_obj.is_valid(), clean_username, form_obj.is_valid(), clean_username, form_obj.is_valid(), clean_username, form_obj.is_valid(), clean_username...........

comment:6 Changed 23 months ago by anonymous

  • Resolution invalid deleted
  • Status changed from closed to new

comment:7 Changed 23 months ago by timo

  • Resolution set to duplicate
  • Status changed from new to closed

It doesn't appear to me that anyone complaining about this has done more investigation than lrekucki did in #18803 so I'm going to re-close it. If you want to reopen, please investigate this more and demonstrate how the problem can be solved.

Note: See TracTickets for help on using tickets.
Back to Top