Fixed #16179 -- Extended argument handling of the new WizardView a little to behave the same as the rest of the generic class based views. Also cleaned up the template loading in its tests a bit. Thanks, Harro van der Klauw.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16368 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-06-11 15:11:56 +00:00
parent 7f68d06c98
commit 703498b1c8
6 changed files with 56 additions and 25 deletions

View File

@ -22,12 +22,6 @@ class NamedWizardTests(object):
self.testuser, created = User.objects.get_or_create(username='testuser1')
self.wizard_step_data[0]['form1-user'] = self.testuser.pk
wizard_template_dirs = [os.path.join(os.path.dirname(wizard.__file__), 'templates')]
settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + wizard_template_dirs
def tearDown(self):
del settings.TEMPLATE_DIRS[-1]
def test_initial_call(self):
response = self.client.get(reverse('%s_start' % self.wizard_urlname))
self.assertEqual(response.status_code, 302)

View File

@ -0,0 +1 @@
{% extends "formtools/wizard/wizard_form.html" %}

View File

@ -13,12 +13,6 @@ class WizardTests(object):
self.testuser, created = User.objects.get_or_create(username='testuser1')
self.wizard_step_data[0]['form1-user'] = self.testuser.pk
wizard_template_dirs = [os.path.join(os.path.dirname(wizard.__file__), 'templates')]
settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + wizard_template_dirs
def tearDown(self):
del settings.TEMPLATE_DIRS[-1]
def test_initial_call(self):
response = self.client.get(self.wizard_url)
wizard = response.context['wizard']
@ -245,4 +239,44 @@ class CookieWizardTests(WizardTests, TestCase):
}
)
class WizardTestKwargs(TestCase):
wizard_url = '/wiz_other_template/'
wizard_step_1_data = {
'cookie_contact_wizard-current_step': 'form1',
}
wizard_step_data = (
{
'form1-name': 'Pony',
'form1-thirsty': '2',
'cookie_contact_wizard-current_step': 'form1',
},
{
'form2-address1': '123 Main St',
'form2-address2': 'Djangoland',
'cookie_contact_wizard-current_step': 'form2',
},
{
'form3-random_crap': 'blah blah',
'cookie_contact_wizard-current_step': 'form3',
},
{
'form4-INITIAL_FORMS': '0',
'form4-TOTAL_FORMS': '2',
'form4-MAX_NUM_FORMS': '0',
'form4-0-random_crap': 'blah blah',
'form4-1-random_crap': 'blah blah',
'cookie_contact_wizard-current_step': 'form4',
}
)
urls = 'django.contrib.formtools.wizard.tests.wizardtests.urls'
def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1')
self.wizard_step_data[0]['form1-user'] = self.testuser.pk
def test_template(self):
templates = os.path.join(os.path.dirname(__file__), 'templates')
with self.settings(
TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]):
response = self.client.get(self.wizard_url)
self.assertTemplateUsed(response, 'other_wizard_form.html')

View File

@ -13,4 +13,10 @@ urlpatterns = patterns('',
('form2', Page2),
('form3', Page3),
('form4', Page4)])),
url(r'^wiz_other_template/$', CookieContactWizard.as_view(
[('form1', Page1),
('form2', Page2),
('form3', Page3),
('form4', Page4)],
template_name='other_wizard_form.html')),
)

View File

@ -111,8 +111,8 @@ class WizardView(TemplateView):
return super(WizardView, cls).as_view(**initkwargs)
@classmethod
def get_initkwargs(cls, form_list,
initial_dict=None, instance_dict=None, condition_dict=None):
def get_initkwargs(cls, form_list, initial_dict=None,
instance_dict=None, condition_dict=None, *args, **kwargs):
"""
Creates a dict with all needed parameters for the form wizard instances.
@ -134,11 +134,11 @@ class WizardView(TemplateView):
will be called with the formwizard instance as the only argument.
If the return value is true, the step's form will be used.
"""
kwargs = {
kwargs.update({
'initial_dict': initial_dict or {},
'instance_dict': instance_dict or {},
'condition_dict': condition_dict or {},
}
})
init_form_list = SortedDict()
assert len(form_list) > 0, 'at least one form is needed'
@ -567,21 +567,16 @@ class NamedUrlWizardView(WizardView):
We require a url_name to reverse URLs later. Additionally users can
pass a done_step_name to change the URL name of the "done" view.
"""
extra_kwargs = {
'done_step_name': 'done'
}
assert 'url_name' in kwargs, 'URL name is needed to resolve correct wizard URLs'
extra_kwargs['url_name'] = kwargs.pop('url_name')
if 'done_step_name' in kwargs:
extra_kwargs['done_step_name'] = kwargs.pop('done_step_name')
extra_kwargs = {
'done_step_name': kwargs.pop('done_step_name', 'done'),
'url_name': kwargs.pop('url_name'),
}
initkwargs = super(NamedUrlWizardView, cls).get_initkwargs(*args, **kwargs)
initkwargs.update(extra_kwargs)
assert initkwargs['done_step_name'] not in initkwargs['form_list'], \
'step name "%s" is reserved for "done" view' % initkwargs['done_step_name']
return initkwargs
def get(self, *args, **kwargs):

View File

@ -29,6 +29,7 @@ ALWAYS_INSTALLED_APPS = [
'django.contrib.admindocs',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.formtools.wizard',
'regressiontests.staticfiles_tests',
'regressiontests.staticfiles_tests.apps.test',
'regressiontests.staticfiles_tests.apps.no_label',