Ticket #6893: form_wizard_patch.diff
File form_wizard_patch.diff, 3.4 KB (added by , 17 years ago) |
---|
-
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 %} -
django/contrib/formtools/tests.py
1 1 from django import newforms as 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.conf import settings 5 5 from django.test import TestCase … … 86 86 response = self.client.post('/test1/', test_data) 87 87 self.assertEqual(response.content, success_string) 88 88 89 class WizardPageOneForm(forms.Form): 90 field = forms.CharField() 91 92 class WizardPageTwoForm(forms.Form): 93 field = forms.CharField() 94 95 class WizardClass(wizard.FormWizard): 96 97 def get_template(self, step): 98 return "formtools/wizard_form.html" 99 100 def done(self, request, cleaned_data): 101 return http.HttpResponse(success_string) 102 103 class DummyRequest(object): 104 """ 105 We'll pass this as request instead of a real request object 106 """ 107 108 def __init__(self, POST=None): 109 self.method = "GET" 110 self.POST = None 111 if POST: 112 self.method = "POST" 113 self.POST = POST 114 115 class WizardTests(TestCase): 116 def test_step_starts_at_zero(self): 117 """ 118 step should be zero for the first form 119 """ 120 wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm]) 121 request = DummyRequest() 122 wizard(request) 123 self.assertEquals(0, wizard.step) 124 125 def test_step_increments(self): 126 """ 127 step should be incremented when we go to the next page 128 """ 129 wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm]) 130 request = DummyRequest(POST={"0-field":"test", "wizard_step":"0"}) 131 response = wizard(request) 132 self.assertEquals(1, wizard.step) 133 134 No newline at end of file -
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,