Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored June 11, 2011
6  django/contrib/formtools/wizard/tests/namedwizardtests/tests.py
@@ -22,12 +22,6 @@ def setUp(self):
22 22
         self.testuser, created = User.objects.get_or_create(username='testuser1')
23 23
         self.wizard_step_data[0]['form1-user'] = self.testuser.pk
24 24
 
25  
-        wizard_template_dirs = [os.path.join(os.path.dirname(wizard.__file__), 'templates')]
26  
-        settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + wizard_template_dirs
27  
-
28  
-    def tearDown(self):
29  
-        del settings.TEMPLATE_DIRS[-1]
30  
-
31 25
     def test_initial_call(self):
32 26
         response = self.client.get(reverse('%s_start' % self.wizard_urlname))
33 27
         self.assertEqual(response.status_code, 302)
1  django/contrib/formtools/wizard/tests/wizardtests/templates/other_wizard_form.html
... ...
@@ -0,0 +1 @@
  1
+{% extends "formtools/wizard/wizard_form.html" %}
46  django/contrib/formtools/wizard/tests/wizardtests/tests.py
@@ -13,12 +13,6 @@ def setUp(self):
13 13
         self.testuser, created = User.objects.get_or_create(username='testuser1')
14 14
         self.wizard_step_data[0]['form1-user'] = self.testuser.pk
15 15
 
16  
-        wizard_template_dirs = [os.path.join(os.path.dirname(wizard.__file__), 'templates')]
17  
-        settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + wizard_template_dirs
18  
-
19  
-    def tearDown(self):
20  
-        del settings.TEMPLATE_DIRS[-1]
21  
-
22 16
     def test_initial_call(self):
23 17
         response = self.client.get(self.wizard_url)
24 18
         wizard = response.context['wizard']
@@ -245,4 +239,44 @@ class CookieWizardTests(WizardTests, TestCase):
245 239
         }
246 240
     )
247 241
 
  242
+class WizardTestKwargs(TestCase):
  243
+    wizard_url = '/wiz_other_template/'
  244
+    wizard_step_1_data = {
  245
+        'cookie_contact_wizard-current_step': 'form1',
  246
+    }
  247
+    wizard_step_data = (
  248
+        {
  249
+            'form1-name': 'Pony',
  250
+            'form1-thirsty': '2',
  251
+            'cookie_contact_wizard-current_step': 'form1',
  252
+        },
  253
+        {
  254
+            'form2-address1': '123 Main St',
  255
+            'form2-address2': 'Djangoland',
  256
+            'cookie_contact_wizard-current_step': 'form2',
  257
+        },
  258
+        {
  259
+            'form3-random_crap': 'blah blah',
  260
+            'cookie_contact_wizard-current_step': 'form3',
  261
+        },
  262
+        {
  263
+            'form4-INITIAL_FORMS': '0',
  264
+            'form4-TOTAL_FORMS': '2',
  265
+            'form4-MAX_NUM_FORMS': '0',
  266
+            'form4-0-random_crap': 'blah blah',
  267
+            'form4-1-random_crap': 'blah blah',
  268
+            'cookie_contact_wizard-current_step': 'form4',
  269
+        }
  270
+    )
  271
+    urls = 'django.contrib.formtools.wizard.tests.wizardtests.urls'
  272
+
  273
+    def setUp(self):
  274
+        self.testuser, created = User.objects.get_or_create(username='testuser1')
  275
+        self.wizard_step_data[0]['form1-user'] = self.testuser.pk
248 276
 
  277
+    def test_template(self):
  278
+        templates = os.path.join(os.path.dirname(__file__), 'templates')
  279
+        with self.settings(
  280
+                TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]):
  281
+            response = self.client.get(self.wizard_url)
  282
+            self.assertTemplateUsed(response, 'other_wizard_form.html')
6  django/contrib/formtools/wizard/tests/wizardtests/urls.py
@@ -13,4 +13,10 @@
13 13
          ('form2', Page2),
14 14
          ('form3', Page3),
15 15
          ('form4', Page4)])),
  16
+     url(r'^wiz_other_template/$', CookieContactWizard.as_view(
  17
+         [('form1', Page1),
  18
+          ('form2', Page2),
  19
+          ('form3', Page3),
  20
+          ('form4', Page4)],
  21
+          template_name='other_wizard_form.html')),
16 22
 )
19  django/contrib/formtools/wizard/views.py
@@ -111,8 +111,8 @@ def as_view(cls, *args, **kwargs):
111 111
         return super(WizardView, cls).as_view(**initkwargs)
112 112
 
113 113
     @classmethod
114  
-    def get_initkwargs(cls, form_list,
115  
-            initial_dict=None, instance_dict=None, condition_dict=None):
  114
+    def get_initkwargs(cls, form_list, initial_dict=None,
  115
+            instance_dict=None, condition_dict=None, *args, **kwargs):
116 116
         """
117 117
         Creates a dict with all needed parameters for the form wizard instances.
118 118
 
@@ -134,11 +134,11 @@ def get_initkwargs(cls, form_list,
134 134
           will be called with the formwizard instance as the only argument.
135 135
           If the return value is true, the step's form will be used.
136 136
         """
137  
-        kwargs = {
  137
+        kwargs.update({
138 138
             'initial_dict': initial_dict or {},
139 139
             'instance_dict': instance_dict or {},
140 140
             'condition_dict': condition_dict or {},
141  
-        }
  141
+        })
142 142
         init_form_list = SortedDict()
143 143
 
144 144
         assert len(form_list) > 0, 'at least one form is needed'
@@ -567,21 +567,16 @@ def get_initkwargs(cls, *args, **kwargs):
567 567
         We require a url_name to reverse URLs later. Additionally users can
568 568
         pass a done_step_name to change the URL name of the "done" view.
569 569
         """
  570
+        assert 'url_name' in kwargs, 'URL name is needed to resolve correct wizard URLs'
570 571
         extra_kwargs = {
571  
-            'done_step_name': 'done'
  572
+            'done_step_name': kwargs.pop('done_step_name', 'done'),
  573
+            'url_name': kwargs.pop('url_name'),
572 574
         }
573  
-        assert 'url_name' in kwargs, 'URL name is needed to resolve correct wizard URLs'
574  
-        extra_kwargs['url_name'] = kwargs.pop('url_name')
575  
-
576  
-        if 'done_step_name' in kwargs:
577  
-            extra_kwargs['done_step_name'] = kwargs.pop('done_step_name')
578  
-
579 575
         initkwargs = super(NamedUrlWizardView, cls).get_initkwargs(*args, **kwargs)
580 576
         initkwargs.update(extra_kwargs)
581 577
 
582 578
         assert initkwargs['done_step_name'] not in initkwargs['form_list'], \
583 579
             'step name "%s" is reserved for "done" view' % initkwargs['done_step_name']
584  
-
585 580
         return initkwargs
586 581
 
587 582
     def get(self, *args, **kwargs):
1  tests/runtests.py
@@ -29,6 +29,7 @@
29 29
     'django.contrib.admindocs',
30 30
     'django.contrib.staticfiles',
31 31
     'django.contrib.humanize',
  32
+    'django.contrib.formtools.wizard',
32 33
     'regressiontests.staticfiles_tests',
33 34
     'regressiontests.staticfiles_tests.apps.test',
34 35
     'regressiontests.staticfiles_tests.apps.no_label',

0 notes on commit 703498b

Please sign in to comment.
Something went wrong with that request. Please try again.