﻿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
17850	Passing FormWizard.as_view(form_list) a dynamic form_list	Jeffrey Horn <jrhorn424@…>	nobody	"The following technique fails to provide the expected behavior. The error returned is:
{{{
TypeError: issubclass() arg 1 must be a class
# happens in
/django/contrib/formtools/wizard/views.py"", line 166, in get_initkwargs
}}}

urls.py:
{{{
from django.conf.urls import patterns, url

# from views import survey_wizard
from views import SurveyWizard
from forms import get_survey_page_list

# I'd rather do this dynamically as well, but this *should* work
survey_page_list = get_survey_page_list('274a442b-67ec-11e1-b010-78ca39b1b597')

urlpatterns = patterns('',
    url(r'^(?P<survey>[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})$', SurveyWizard.as_view(form_list=survey_page_list)),
)
}}}

forms.py:
{{{
def get_survey_page_list(survey):
    """"""
    Build a list of survey pages for the form wizard to use.

    args:
        survey - a unicode string passed in from a URL parameter
    """"""
    survey_page_list = []

    # Since we're receiving a captured URL parameter, we have to use that
    # string to acutally fetch the survey object.
    s = Survey.objects.get(pk=survey)
    for page in s.page_set.all().order_by('number'):
        step_name = unicode(page.number)
        form_class = make_survey_page_form(survey, page.number)
        survey_page_list.append((step_name, form_class))

    return SortedDict(survey_page_list)
}}}

Looking into the Werkzeug debugger reveals that the functions called in forms.py are grabbing and returning a SortedDict of forms:
{{{
>>> dir()
['args', 'cls', 'condition_dict', 'form', 'form_list', 'i', 'init_form_list', 'initial_dict',   ]
>>> form_list
django.utils.datastructures.SortedDict({u'1': <class 'mysite.survey.forms._SurveyPageForm'>, u'2': <class 'mysite.survey.forms._SurveyPageForm'>, u'3': <class 'mysite.survey.forms._SurveyPageForm'>})
>>> initial_dict
>>> init_form_list
django.utils.datastructures.SortedDict({u'0': u'1', u'1': u'2', u'2': u'3'})
}}}"	New feature	closed	contrib.formtools	1.4-beta-1	Normal	wontfix	formwizard	kristoffer.snabb@…	Design decision needed	0	0	0	0	0	0
