Ticket #6893: form_wizard_patch_2.diff

File form_wizard_patch_2.diff, 3.3 KB (added by wamberg, 16 years ago)

Updated patch to r8172

  • 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,
  • django/contrib/formtools/tests.py

     
    11from django import forms
    2 from django.contrib.formtools import preview
     2from django.contrib.formtools import preview, wizard
    33from django import http
    44from django.test import TestCase
    55
     
    8585        response = self.client.post('/test1/', test_data)
    8686        self.assertEqual(response.content, success_string)
    8787
     88class WizardPageOneForm(forms.Form):
     89    field = forms.CharField()
     90   
     91class WizardPageTwoForm(forms.Form):
     92    field = forms.CharField()
     93   
     94class 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
     102class 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
     114class 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 %}
Back to Top