Ticket #19189: ticket_19189.diff
File ticket_19189.diff, 5.7 KB (added by , 12 years ago) |
---|
-
django/contrib/formtools/tests/wizard/__init__.py
diff --git a/django/contrib/formtools/tests/wizard/__init__.py b/django/contrib/formtools/tests/wizard/__init__.py index a2a9692..c025a08 100644
a b from django.contrib.formtools.tests.wizard.wizardtests.tests import ( 16 16 WizardTestKwargs, 17 17 WizardTestGenericViewInterface, 18 18 WizardFormKwargsOverrideTests, 19 WizardRevalidationTests, 19 20 ) -
django/contrib/formtools/tests/wizard/wizardtests/forms.py
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/forms.py b/django/contrib/formtools/tests/wizard/wizardtests/forms.py index 6a81329..1127b29 100644
a b class SessionContactWizard(ContactWizard): 65 65 class CookieContactWizard(ContactWizard): 66 66 storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage' 67 67 68 class EmptyPage1(forms.Form): 69 on_page1 = forms.NullBooleanField() 70 71 class EmptyPage2(forms.Form): 72 on_page2 = forms.NullBooleanField() 73 74 class EmptyPage3(forms.Form): 75 on_page3 = forms.NullBooleanField() 76 77 class RevalidationWizard(SessionContactWizard): 78 def done(self, form_list, **kwargs): 79 step = self.form_list.keys()[1] 80 form = form_list[1] 81 raise self.RevalidationError(step, form, **kwargs) 82 -
django/contrib/formtools/tests/wizard/wizardtests/tests.py
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py index 586bd59..761d1fd 100644
a b class WizardFormKwargsOverrideTests(TestCase): 385 385 self.assertEqual(formset.initial_form_count(), 1) 386 386 self.assertEqual(['staff@example.com'], 387 387 list(formset.queryset.values_list('email', flat=True))) 388 389 class WizardRevalidationTests(TestCase): 390 urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls' 391 392 wizard_url = '/wiz_revalidation/' 393 wizard_step_1_data = { 394 'revalidation_wizard-current_step': 'form1', 395 } 396 wizard_step_data = ( 397 { 398 'revalidation_wizard-current_step': 'form1', 399 }, 400 { 401 'revalidation_wizard-current_step': 'form2', 402 }, 403 { 404 'revalidation_wizard-current_step': 'form3', 405 }, 406 ) 407 408 def test_form_revalidate(self): 409 response = self.client.get(self.wizard_url) 410 self.assertEqual(response.status_code, 200) 411 self.assertEqual(response.context['wizard']['steps'].current, 'form1') 412 413 response = self.client.post(self.wizard_url, self.wizard_step_data[0]) 414 self.assertEqual(response.status_code, 200) 415 self.assertEqual(response.context['wizard']['steps'].current, 'form2') 416 417 post_data = self.wizard_step_data[1] 418 response = self.client.post(self.wizard_url, post_data) 419 self.assertEqual(response.status_code, 200) 420 self.assertEqual(response.context['wizard']['steps'].current, 'form3') 421 422 response = self.client.post(self.wizard_url, self.wizard_step_data[2]) 423 self.assertEqual(response.status_code, 200) 424 self.assertEqual(response.context['wizard']['steps'].current, 'form2') 425 -
django/contrib/formtools/tests/wizard/wizardtests/urls.py
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/urls.py b/django/contrib/formtools/tests/wizard/wizardtests/urls.py index dabce53..f15e2dd 100644
a b from django.conf.urls import patterns, url 2 2 from django.contrib.formtools.tests.wizard.wizardtests.forms import ( 3 3 SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4) 4 4 5 from django.contrib.formtools.tests.wizard.wizardtests.forms import ( 6 RevalidationWizard, EmptyPage1, EmptyPage2, EmptyPage3) 7 5 8 urlpatterns = patterns('', 6 9 url(r'^wiz_session/$', SessionContactWizard.as_view( 7 10 [('form1', Page1), … … urlpatterns = patterns('', 19 22 ('form3', Page3), 20 23 ('form4', Page4)], 21 24 template_name='other_wizard_form.html')), 25 url(r'^wiz_revalidation/$', RevalidationWizard.as_view( 26 [('form1', EmptyPage1), 27 ('form2', EmptyPage2), 28 ('form3', EmptyPage3)])), 22 29 ) -
django/contrib/formtools/wizard/views.py
diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index ea41e86..2119301 100644
a b class WizardView(TemplateView): 307 307 self.storage.current_step = next_step 308 308 return self.render(new_form, **kwargs) 309 309 310 class RevalidationError(Exception): 311 def __init__(self, step, form, **kwargs): 312 self.step = step 313 self.form = form 314 self.kwargs = kwargs 315 316 def __repr__(self): 317 return '%s(%s)' % (self.__class__, self.step) 318 __str__ = __repr__ 319 310 320 def render_done(self, form, **kwargs): 311 321 """ 312 322 This method gets called when all forms passed. The method should also … … class WizardView(TemplateView): 327 337 # render the done view and reset the wizard before returning the 328 338 # response. This is needed to prevent from rendering done with the 329 339 # same data twice. 330 done_response = self.done(final_form_list, **kwargs) 340 try: 341 done_response = self.done(final_form_list, **kwargs) 342 except self.RevalidationError as e: 343 return self.render_revalidation_failure(e.step, e.form, **e.kwargs) 344 331 345 self.storage.reset() 332 346 return done_response 333 347