diff --git a/django/contrib/formtools/wizard/tests/namedwizardtests/tests.py b/django/contrib/formtools/wizard/tests/namedwizardtests/tests.py index cc442d7294..19ac7d6d7b 100644 --- a/django/contrib/formtools/wizard/tests/namedwizardtests/tests.py +++ b/django/contrib/formtools/wizard/tests/namedwizardtests/tests.py @@ -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) diff --git a/django/contrib/formtools/wizard/tests/wizardtests/templates/other_wizard_form.html b/django/contrib/formtools/wizard/tests/wizardtests/templates/other_wizard_form.html new file mode 100644 index 0000000000..45f812cbae --- /dev/null +++ b/django/contrib/formtools/wizard/tests/wizardtests/templates/other_wizard_form.html @@ -0,0 +1 @@ +{% extends "formtools/wizard/wizard_form.html" %} diff --git a/django/contrib/formtools/wizard/tests/wizardtests/tests.py b/django/contrib/formtools/wizard/tests/wizardtests/tests.py index f64b2ba303..b07f286590 100644 --- a/django/contrib/formtools/wizard/tests/wizardtests/tests.py +++ b/django/contrib/formtools/wizard/tests/wizardtests/tests.py @@ -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') diff --git a/django/contrib/formtools/wizard/tests/wizardtests/urls.py b/django/contrib/formtools/wizard/tests/wizardtests/urls.py index e305397a37..7b5e84e234 100644 --- a/django/contrib/formtools/wizard/tests/wizardtests/urls.py +++ b/django/contrib/formtools/wizard/tests/wizardtests/urls.py @@ -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')), ) diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index 614837b34b..ac9cfbdb10 100644 --- a/django/contrib/formtools/wizard/views.py +++ b/django/contrib/formtools/wizard/views.py @@ -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): diff --git a/tests/runtests.py b/tests/runtests.py index 6da3299de6..31bb074e67 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -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',