Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #16179 -- Extended argument handling of the new WizardView a li…

…ttle 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
  • Loading branch information...
commit 703498b1c86678c287de8a44c08724b4e67c4e40 1 parent 7f68d06
@jezdez jezdez authored
View
6 django/contrib/formtools/wizard/tests/namedwizardtests/tests.py
@@ -22,12 +22,6 @@ def setUp(self):
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
1  django/contrib/formtools/wizard/tests/wizardtests/templates/other_wizard_form.html
@@ -0,0 +1 @@
+{% extends "formtools/wizard/wizard_form.html" %}
View
46 django/contrib/formtools/wizard/tests/wizardtests/tests.py
@@ -13,12 +13,6 @@ def setUp(self):
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
6 django/contrib/formtools/wizard/tests/wizardtests/urls.py
@@ -13,4 +13,10 @@
('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
19 django/contrib/formtools/wizard/views.py
@@ -111,8 +111,8 @@ def as_view(cls, *args, **kwargs):
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 @@ def get_initkwargs(cls, form_list,
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 @@ def get_initkwargs(cls, *args, **kwargs):
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.
"""
+ assert 'url_name' in kwargs, 'URL name is needed to resolve correct wizard URLs'
extra_kwargs = {
- 'done_step_name': 'done'
+ 'done_step_name': kwargs.pop('done_step_name', 'done'),
+ 'url_name': kwargs.pop('url_name'),
}
- 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')
-
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
1  tests/runtests.py
@@ -29,6 +29,7 @@
'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',
Please sign in to comment.
Something went wrong with that request. Please try again.