Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#18803 closed Bug (fixed)

Django FormWizard.as_view condition_dict callable called multiple times?

Reported by: mikewatsup@… Owned by: nobody
Component: contrib.formtools Version: 1.4
Severity: Release blocker Keywords: form wizard, as_view, condition_dict argument
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The following is a snippet of how I have setup my FormWizard. When I hit this view function, 'bar' gets printed once and 'foo' gets printed 7 times:

# views.py
def _show_repair_item_form_condition(wizard):
    print 'foo'
    return True

@login_required
def workshop(request):
    print 'bar'
    cw = WorkshopWizard.as_view([WorkshopRepairItemFormSet, EmptyForm], condition_dict={'0': _show_repair_item_form_condition})
    return cw(request)

I have looked at the implmentation of the as_view function and can't find any trace of a bug causing this to happen. There is no documentation on the web about this issue either.

Any ideas?

Thanks, Mike

Change History (3)

comment:1 by Łukasz Rekucki, 12 years ago

This isn't a bug. The wizard doesn't make any guarantees about calling the conditions only once. On the contrary, the whole point of having a callable is being able to dynamically adjust the list of forms based on validation results (so the form_list will differ between validation and rendering).

PS. The as_view() method is intended to be called only once per life of application (usually in urls.py), not on every request. While it's not an error to do so, it's a bit inefficient.

comment:2 by Łukasz Rekucki, 12 years ago

Resolution: invalid
Status: newclosed

comment:3 by JasonL.Thompson <thompso575@…>, 11 years ago

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