Ticket #17148: trac-17148.diff
File trac-17148.diff, 6.2 KB (added by , 13 years ago) |
---|
-
django/contrib/formtools/tests/wizard/__init__.py
diff --git a/django/contrib/formtools/tests/wizard/__init__.py b/django/contrib/formtools/tests/wizard/__init__.py index dce2fed..7b15fb5 100644
a b from django.contrib.formtools.tests.wizard.wizardtests.tests import ( 14 14 SessionWizardTests, 15 15 CookieWizardTests, 16 16 WizardTestKwargs, 17 WizardTestGenericViewInterface, 17 18 ) -
django/contrib/formtools/tests/wizard/wizardtests/tests.py
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py index 9868721..3eb77cb 100644
a b 1 1 from __future__ import with_statement 2 2 import os 3 3 4 from django import forms 4 5 from django.test import TestCase 6 from django.test.client import RequestFactory 5 7 from django.conf import settings 6 8 from django.contrib.auth.models import User 9 from django.contrib.formtools.wizard.views import CookieWizardView 7 10 8 11 9 12 class WizardTests(object): … … class WizardTestKwargs(TestCase): 280 283 TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]): 281 284 response = self.client.get(self.wizard_url) 282 285 self.assertTemplateUsed(response, 'other_wizard_form.html') 286 287 288 class WizardTestGenericViewInterface(TestCase): 289 def test_get_context_data_inheritance(self): 290 class TestWizard(CookieWizardView): 291 """ 292 A subclass that implements ``get_context_data`` using the standard 293 protocol for generic views (accept only **kwargs). 294 295 See ticket #17148. 296 """ 297 def get_context_data(self, **kwargs): 298 context = super(TestWizard, self).get_context_data(**kwargs) 299 context['test_key'] = 'test_value' 300 return context 301 302 factory = RequestFactory() 303 view = TestWizard.as_view([forms.Form]) 304 305 response = view(factory.get('/')) 306 self.assertEquals(response.context_data['test_key'], 'test_value') 307 308 def test_get_context_data_with_mixin(self): 309 class AnotherMixin(object): 310 def get_context_data(self, **kwargs): 311 context = super(AnotherMixin, self).get_context_data(**kwargs) 312 context['another_key'] = 'another_value' 313 return context 314 315 class TestWizard(AnotherMixin, CookieWizardView): 316 """ 317 A subclass that implements ``get_context_data`` using the standard 318 protocol for generic views (accept only **kwargs). 319 320 See ticket #17148. 321 """ 322 def get_context_data(self, **kwargs): 323 context = super(TestWizard, self).get_context_data(**kwargs) 324 context['test_key'] = 'test_value' 325 return context 326 327 factory = RequestFactory() 328 329 view = TestWizard.as_view([forms.Form]) 330 331 response = view(factory.get('/')) 332 self.assertEquals(response.context_data['test_key'], 'test_value') 333 self.assertEquals(response.context_data['another_key'], 'another_value') -
django/contrib/formtools/wizard/views.py
diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index 15ba146..0e1486c 100644
a b class WizardView(TemplateView): 497 497 step = self.steps.current 498 498 return self.get_form_list().keyOrder.index(step) 499 499 500 def get_context_data(self, form, * args, **kwargs):500 def get_context_data(self, form, **kwargs): 501 501 """ 502 502 Returns the template context for a step. You can overwrite this method 503 503 to add more data for all or some steps. This method returns a … … class WizardView(TemplateView): 514 514 515 515 class MyWizard(FormWizard): 516 516 def get_context_data(self, form, **kwargs): 517 context = super(MyWizard, self).get_context_data(form , **kwargs)517 context = super(MyWizard, self).get_context_data(form=form, **kwargs) 518 518 if self.steps.current == 'my_step_name': 519 519 context.update({'another_var': True}) 520 520 return context 521 521 """ 522 context = super(WizardView, self).get_context_data(* args, **kwargs)522 context = super(WizardView, self).get_context_data(**kwargs) 523 523 context.update(self.storage.extra_data) 524 524 context['wizard'] = { 525 525 'form': form, … … class WizardView(TemplateView): 535 535 Returns a ``HttpResponse`` containing all needed context data. 536 536 """ 537 537 form = form or self.get_form() 538 context = self.get_context_data(form , **kwargs)538 context = self.get_context_data(form=form, **kwargs) 539 539 return self.render_to_response(context) 540 540 541 541 def done(self, form_list, **kwargs): … … class NamedUrlCookieWizardView(NamedUrlWizardView): 683 683 A NamedUrlFormWizard with pre-configured CookieStorageBackend. 684 684 """ 685 685 storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage' 686 -
docs/ref/contrib/formtools/form-wizard.txt
diff --git a/docs/ref/contrib/formtools/form-wizard.txt b/docs/ref/contrib/formtools/form-wizard.txt index aadd7d2..4c071c1 100644
a b Advanced ``WizardView`` methods 309 309 Example to add extra variables for a specific step:: 310 310 311 311 def get_context_data(self, form, **kwargs): 312 context = super(MyWizard, self).get_context_data(form , **kwargs)312 context = super(MyWizard, self).get_context_data(form=form, **kwargs) 313 313 if self.steps.current == 'my_step_name': 314 314 context.update({'another_var': True}) 315 315 return context … … Advanced ``WizardView`` methods 436 436 437 437 def render(self, form=None, **kwargs): 438 438 form = form or self.get_form() 439 context = self.get_context_data(form , **kwargs)439 context = self.get_context_data(form=form, **kwargs) 440 440 return self.render_to_response(context) 441 441 442 442 Providing initial data for the forms