Code

Opened 20 months ago

Closed 18 months ago

Last modified 12 months 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

Attachments (0)

Change History (3)

comment:1 Changed 18 months ago by lrekucki

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

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 Changed 18 months ago by lrekucki

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

comment:3 Changed 12 months ago by JasonL.Thompson <thompso575@…>

  • Resolution changed from invalid to fixed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.