diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py
index b5037f4..be0372a 100644
a
|
b
|
class WizardTests(TestCase):
|
322 | 322 | response = self.client.post('/wizard/', data) |
323 | 323 | self.assertEqual(2, response.context['step0']) |
324 | 324 | |
| 325 | def test_11726(self): |
| 326 | """ |
| 327 | Regression test for ticket #11726. |
| 328 | Wizard should not raise Http404 when steps are added dynamically. |
| 329 | """ |
| 330 | reached = [False] |
| 331 | that = self |
| 332 | |
| 333 | class WizardWithProcessStep(WizardClass): |
| 334 | def process_step(self, request, form, step): |
| 335 | if step == 0: |
| 336 | if self.num_steps() < 2: |
| 337 | self.form_list.append(WizardPageTwoForm) |
| 338 | if step == 1: |
| 339 | that.assertTrue(isinstance(form, WizardPageTwoForm)) |
| 340 | reached[0] = True |
| 341 | |
| 342 | wizard = WizardWithProcessStep([WizardPageOneForm]) |
| 343 | data = {"0-field": "test", |
| 344 | "1-field": "test2", |
| 345 | "hash_0": "7e9cea465f6a10a6fb47fcea65cb9a76350c9a5c", |
| 346 | "wizard_step": "1"} |
| 347 | wizard(DummyRequest(POST=data)) |
| 348 | self.assertTrue(reached[0]) |
| 349 | |
| 350 | data = {"0-field": "test", |
| 351 | "1-field": "test2", |
| 352 | "hash_0": "7e9cea465f6a10a6fb47fcea65cb9a76350c9a5c", |
| 353 | "hash_1": "d5b434e3934cc92fee4bd2964c4ebc06f81d362d", |
| 354 | "wizard_step": "2"} |
| 355 | self.assertRaises(http.Http404, wizard, DummyRequest(POST=data)) |
| 356 | |
325 | 357 | def test_14498(self): |
326 | 358 | """ |
327 | 359 | Regression test for ticket #14498. All previous steps' forms should be |
diff --git a/django/contrib/formtools/wizard.py b/django/contrib/formtools/wizard.py
index af6f97b..c19578c 100644
a
|
b
|
class FormWizard(object):
|
47 | 47 | |
48 | 48 | def get_form(self, step, data=None): |
49 | 49 | "Helper method that returns the Form instance for the given step." |
| 50 | # Sanity check. |
| 51 | if step >= self.num_steps(): |
| 52 | raise Http404('Step %s does not exist' % step) |
50 | 53 | return self.form_list[step](data, prefix=self.prefix_for_step(step), initial=self.initial.get(step, None)) |
51 | 54 | |
52 | 55 | def num_steps(self): |
… |
… |
class FormWizard(object):
|
71 | 74 | current_step = self.determine_step(request, *args, **kwargs) |
72 | 75 | self.parse_params(request, *args, **kwargs) |
73 | 76 | |
74 | | # Sanity check. |
75 | | if current_step >= self.num_steps(): |
76 | | raise Http404('Step %s does not exist' % current_step) |
77 | | |
78 | 77 | # Validate and process all the previous forms before instantiating the |
79 | 78 | # current step's form in case self.process_step makes changes to |
80 | 79 | # self.form_list. |