Ticket #6893: form_wizard_patch_2.diff
File form_wizard_patch_2.diff, 3.3 KB (added by , 16 years ago) |
---|
-
django/contrib/formtools/wizard.py
90 90 # Otherwise, move along to the next step. 91 91 else: 92 92 form = self.get_form(next_step) 93 current_step = next_step93 self.step = current_step = next_step 94 94 95 95 return self.render(form, request, current_step) 96 96 … … 209 209 """ 210 210 context = context or {} 211 211 context.update(self.extra_context) 212 return render_to_response(self.get_template(s elf.step), dict(context,212 return render_to_response(self.get_template(step), dict(context, 213 213 step_field=self.step_field_name, 214 214 step0=step, 215 215 step=step + 1, -
django/contrib/formtools/tests.py
1 1 from django import forms 2 from django.contrib.formtools import preview 2 from django.contrib.formtools import preview, wizard 3 3 from django import http 4 4 from django.test import TestCase 5 5 … … 85 85 response = self.client.post('/test1/', test_data) 86 86 self.assertEqual(response.content, success_string) 87 87 88 class WizardPageOneForm(forms.Form): 89 field = forms.CharField() 90 91 class WizardPageTwoForm(forms.Form): 92 field = forms.CharField() 93 94 class WizardClass(wizard.FormWizard): 95 96 def get_template(self, step): 97 return "formtools/wizard_form.html" 98 99 def done(self, request, cleaned_data): 100 return http.HttpResponse(success_string) 101 102 class DummyRequest(object): 103 """ 104 We'll pass this as request instead of a real request object 105 """ 106 107 def __init__(self, POST=None): 108 self.method = "GET" 109 self.POST = None 110 if POST: 111 self.method = "POST" 112 self.POST = POST 113 114 class WizardTests(TestCase): 115 def test_step_starts_at_zero(self): 116 """ 117 step should be zero for the first form 118 """ 119 wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm]) 120 request = DummyRequest() 121 wizard(request) 122 self.assertEquals(0, wizard.step) 123 124 def test_step_increments(self): 125 """ 126 step should be incremented when we go to the next page 127 """ 128 wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm]) 129 request = DummyRequest(POST={"0-field":"test", "wizard_step":"0"}) 130 response = wizard(request) 131 self.assertEquals(1, wizard.step) 132 -
django/contrib/formtools/templates/formtools/wizard_form.html
1 {% extends "base.html" %} 2 3 {% block content %} 4 <p>Step {{ step }} of {{ step_count }}</p> 5 <form action="." method="post"> 6 <table> 7 {{ form }} 8 </table> 9 <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> 10 {{ previous_fields|safe }} 11 <input type="submit"> 12 </form> 13 {% endblock %}