Ticket #17148: trac-17148.diff

File trac-17148.diff, 6.2 KB (added by steph, 13 years ago)

Updated patch and extended tests

  • 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 (  
    1414    SessionWizardTests,
    1515    CookieWizardTests,
    1616    WizardTestKwargs,
     17    WizardTestGenericViewInterface,
    1718)
  • 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  
    11from __future__ import with_statement
    22import os
    33
     4from django import forms
    45from django.test import TestCase
     6from django.test.client import RequestFactory
    57from django.conf import settings
    68from django.contrib.auth.models import User
     9from django.contrib.formtools.wizard.views import CookieWizardView
    710
    811
    912class WizardTests(object):
    class WizardTestKwargs(TestCase):  
    280283                TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]):
    281284            response = self.client.get(self.wizard_url)
    282285            self.assertTemplateUsed(response, 'other_wizard_form.html')
     286
     287
     288class 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):  
    497497            step = self.steps.current
    498498        return self.get_form_list().keyOrder.index(step)
    499499
    500     def get_context_data(self, form, *args, **kwargs):
     500    def get_context_data(self, form, **kwargs):
    501501        """
    502502        Returns the template context for a step. You can overwrite this method
    503503        to add more data for all or some steps. This method returns a
    class WizardView(TemplateView):  
    514514
    515515            class MyWizard(FormWizard):
    516516                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)
    518518                    if self.steps.current == 'my_step_name':
    519519                        context.update({'another_var': True})
    520520                    return context
    521521        """
    522         context = super(WizardView, self).get_context_data(*args, **kwargs)
     522        context = super(WizardView, self).get_context_data(**kwargs)
    523523        context.update(self.storage.extra_data)
    524524        context['wizard'] = {
    525525            'form': form,
    class WizardView(TemplateView):  
    535535        Returns a ``HttpResponse`` containing all needed context data.
    536536        """
    537537        form = form or self.get_form()
    538         context = self.get_context_data(form, **kwargs)
     538        context = self.get_context_data(form=form, **kwargs)
    539539        return self.render_to_response(context)
    540540
    541541    def done(self, form_list, **kwargs):
    class NamedUrlCookieWizardView(NamedUrlWizardView):  
    683683    A NamedUrlFormWizard with pre-configured CookieStorageBackend.
    684684    """
    685685    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  
    309309    Example to add extra variables for a specific step::
    310310
    311311        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)
    313313            if self.steps.current == 'my_step_name':
    314314                context.update({'another_var': True})
    315315            return context
    Advanced ``WizardView`` methods  
    436436
    437437        def render(self, form=None, **kwargs):
    438438            form = form or self.get_form()
    439             context = self.get_context_data(form, **kwargs)
     439            context = self.get_context_data(form=form, **kwargs)
    440440            return self.render_to_response(context)
    441441
    442442Providing initial data for the forms
Back to Top