Django

Code

Changeset 8603

Show
Ignore:
Timestamp:
08/26/08 16:33:56 (3 months ago)
Author:
jacob
Message:

Fixed #6893: FormWizard now properly updates its step value. Thanks, siddhi and wamberg.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/formtools/tests.py

    r8597 r8603  
    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 
     
    102102        self.assertEqual(response.content, success_string) 
    103103 
     104# 
     105# FormWizard tests 
     106# 
     107 
     108class WizardPageOneForm(forms.Form): 
     109    field = forms.CharField() 
     110 
     111class WizardPageTwoForm(forms.Form): 
     112    field = forms.CharField() 
     113 
     114class WizardClass(wizard.FormWizard): 
     115    def render_template(self, *args, **kw): 
     116        return "" 
     117 
     118    def done(self, request, cleaned_data): 
     119        return http.HttpResponse(success_string) 
     120 
     121class DummyRequest(object): 
     122    def __init__(self, POST=None): 
     123        self.method = POST and "POST" or "GET" 
     124        self.POST = POST 
     125 
     126class WizardTests(TestCase): 
     127    def test_step_starts_at_zero(self): 
     128        """ 
     129        step should be zero for the first form 
     130        """ 
     131        wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm]) 
     132        request = DummyRequest() 
     133        wizard(request) 
     134        self.assertEquals(0, wizard.step) 
     135 
     136    def test_step_increments(self): 
     137        """ 
     138        step should be incremented when we go to the next page 
     139        """ 
     140        wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm]) 
     141        request = DummyRequest(POST={"0-field":"test", "wizard_step":"0"}) 
     142        response = wizard(request) 
     143        self.assertEquals(1, wizard.step) 
     144 
  • django/trunk/django/contrib/formtools/wizard.py

    r8597 r8603  
    9393            else: 
    9494                form = self.get_form(next_step) 
    95                 current_step = next_step 
     95                self.step = current_step = next_step 
    9696 
    9797        return self.render(form, request, current_step) 
     
    204204        context = context or {} 
    205205        context.update(self.extra_context) 
    206         return render_to_response(self.get_template(self.step), dict(context, 
     206        return render_to_response(self.get_template(step), dict(context, 
    207207            step_field=self.step_field_name, 
    208208            step0=step,