Ticket #17677: 17677-2.diff
File 17677-2.diff, 5.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 732c02f..a2a9692 100644
a b from django.contrib.formtools.tests.wizard.wizardtests.tests import ( 15 15 CookieWizardTests, 16 16 WizardTestKwargs, 17 17 WizardTestGenericViewInterface, 18 WizardFormKwargsOverrideTests, 18 19 ) -
django/contrib/formtools/tests/wizard/wizardtests/forms.py
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/forms.py b/django/contrib/formtools/tests/wizard/wizardtests/forms.py index 9013e89..6a81329 100644
a b import os 2 2 import tempfile 3 3 4 4 from django import forms 5 from django.contrib.auth.models import User 5 6 from django.core.files.storage import FileSystemStorage 6 7 from django.forms.formsets import formset_factory 8 from django.forms.models import modelformset_factory 7 9 from django.http import HttpResponse 8 10 from django.template import Template, Context 9 11 … … class ContactWizard(WizardView): 50 52 context.update({'another_var': True}) 51 53 return context 52 54 55 class UserForm(forms.ModelForm): 56 class Meta: 57 model = User 58 fields = ('username', 'email') 59 60 UserFormSet = modelformset_factory(User, form=UserForm) 61 53 62 class SessionContactWizard(ContactWizard): 54 63 storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage' 55 64 -
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 592065e..862ef3d 100644
a b from django.test.client import RequestFactory 7 7 from django.conf import settings 8 8 from django.contrib.auth.models import User 9 9 from django.contrib.formtools.wizard.views import CookieWizardView 10 from django.contrib.formtools.tests.wizard.forms import UserForm, UserFormSet 10 11 11 12 12 13 class WizardTests(object): … … class WizardTestGenericViewInterface(TestCase): 331 332 response = view(factory.get('/')) 332 333 self.assertEquals(response.context_data['test_key'], 'test_value') 333 334 self.assertEquals(response.context_data['another_key'], 'another_value') 335 336 337 class WizardFormKwargsOverrideTests(TestCase): 338 def setUp(self): 339 super(WizardFormKwargsOverrideTests, self).setUp() 340 341 # Create two users so we can filter by is_staff when handing our 342 # wizard a queryset keyword argument. 343 User.objects.create(username='test1', email='test1@example.com') 344 User.objects.create(username='test2', email='test2@example.com', 345 is_staff=True) 346 347 def test_instance_is_maintained(self): 348 class InstanceOverrideWizard(CookieWizardView): 349 def get_form_kwargs(self, step): 350 return {'instance': User.objects.get(is_staff=True)} 351 352 factory = RequestFactory() 353 354 view = InstanceOverrideWizard.as_view([UserForm]) 355 response = view(factory.get('/')) 356 357 form = response.context_data['wizard']['form'] 358 359 self.assertNotEqual(form.instance.pk, None) 360 self.assertEqual('test2@example.com', form.initial.get('email', None)) 361 362 def test_queryset_is_maintained(self): 363 class QuerySetOverrideWizard(CookieWizardView): 364 def get_form_kwargs(self, step): 365 return {'queryset': User.objects.filter(is_staff=True)} 366 367 factory = RequestFactory() 368 369 view = QuerySetOverrideWizard.as_view([UserFormSet]) 370 response = view(factory.get('/')) 371 372 formset = response.context_data['wizard']['form'] 373 374 self.assertNotEqual(formset.queryset, None) 375 self.assertEqual(1, formset.initial_form_count()) 376 self.assertEqual(['test2@example.com'], 377 list(formset.queryset.values_list('email', flat=True))) -
django/contrib/formtools/wizard/views.py
diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index 06a0398..4372c8a 100644
a b class WizardView(TemplateView): 385 385 'initial': self.get_form_initial(step), 386 386 }) 387 387 if issubclass(self.form_list[step], forms.ModelForm): 388 # If the form is based on ModelForm, add instance if available. 389 kwargs.update({'instance': self.get_form_instance(step)}) 388 # If the form is based on ModelForm, add instance if available 389 # and not previously set. 390 kwargs.setdefault('instance', self.get_form_instance(step)) 390 391 elif issubclass(self.form_list[step], forms.models.BaseModelFormSet): 391 # If the form is based on ModelFormSet, add queryset if available. 392 kwargs.update({'queryset': self.get_form_instance(step)}) 392 # If the form is based on ModelFormSet, add queryset if available 393 # and not previous set. 394 kwargs.setdefault('queryset', self.get_form_instance(step)) 393 395 return self.form_list[step](**kwargs) 394 396 395 397 def process_step(self, form):