Ticket #6893: form_wizard_patch.diff

File form_wizard_patch.diff, 3.4 KB (added by siddhi, 7 years ago)

Patch for the code and test cases for this bug

  • 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

     
    11from django import newforms as forms
    2 from django.contrib.formtools import preview
     2from django.contrib.formtools import preview, wizard
    33from django import http
    44from django.conf import settings
    55from django.test import TestCase
     
    8686        response = self.client.post('/test1/', test_data)
    8787        self.assertEqual(response.content, success_string)
    8888
     89class WizardPageOneForm(forms.Form):
     90    field = forms.CharField()
     91   
     92class WizardPageTwoForm(forms.Form):
     93    field = forms.CharField()
     94   
     95class 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
     103class 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
     115class 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

     
    9090            # Otherwise, move along to the next step.
    9191            else:
    9292                form = self.get_form(next_step)
    93                 current_step = next_step
     93                self.step = current_step = next_step
    9494
    9595        return self.render(form, request, current_step)
    9696
     
    209209        """
    210210        context = context or {}
    211211        context.update(self.extra_context)
    212         return render_to_response(self.get_template(self.step), dict(context,
     212        return render_to_response(self.get_template(step), dict(context,
    213213            step_field=self.step_field_name,
    214214            step0=step,
    215215            step=step + 1,
Back to Top