Ticket #17677: 17677.diff
File 17677.diff, 5.2 KB (added by , 13 years ago) |
---|
-
django/contrib/formtools/wizard/views.py
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): -
django/contrib/formtools/tests/wizard/wizardtests/views.py
1 from django.contrib.auth.models import User 2 from django.contrib.formtools.wizard.views import CookieWizardView 3 4 5 class ModelWizard(CookieWizardView): 6 7 def get_form_kwargs(self, step): 8 return {'instance': User.objects.get(is_staff=True)} 9 10 11 class QuerySetWizard(CookieWizardView): 12 13 def get_form_kwargs(self, step): 14 return {'queryset': User.objects.filter(is_staff=True)} -
django/contrib/formtools/tests/wizard/wizardtests/tests.py
331 331 response = view(factory.get('/')) 332 332 self.assertEquals(response.context_data['test_key'], 'test_value') 333 333 self.assertEquals(response.context_data['another_key'], 'another_value') 334 335 336 class WizardModelTests(TestCase): 337 338 def setUp(self): 339 super(WizardModelTests, self).setUp() 340 # Create two users so we can filter by is_staff when handing our 341 # wizard a queryset keyword argument. 342 User.objects.create(username='test1', email='test1@example.com') 343 User.objects.create(username='test2', email='test2@example.com', 344 is_staff=True) 345 346 def test_instance_is_maintained(self): 347 from .forms import UserForm 348 from .views import ModelWizard 349 350 factory = RequestFactory() 351 352 view = ModelWizard.as_view([UserForm]) 353 response = view(factory.get('/')) 354 355 instance = response.context_data['wizard']['form'].instance 356 357 self.assertNotEqual(None, instance.pk) 358 self.assertEqual('test2@example.com', instance.email) 359 360 def test_queryset_is_maintained(self): 361 from .forms import UserFormSet 362 from .views import QuerySetWizard 363 364 factory = RequestFactory() 365 366 view = QuerySetWizard.as_view([UserFormSet]) 367 response = view(factory.get('/')) 368 369 formset = response.context_data['wizard']['form'] 370 queryset = formset.queryset 371 emails = list(queryset.values_list('email', flat=True)) 372 373 self.assertNotEqual(None, queryset) 374 self.assertEqual(1, formset.total_form_count()) 375 self.assertEqual(['test2@example.com'], emails) -
django/contrib/formtools/tests/wizard/wizardtests/forms.py
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 … … 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, extra=0) 61 53 62 class SessionContactWizard(ContactWizard): 54 63 storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage' 55 64 -
django/contrib/formtools/tests/wizard/__init__.py
15 15 CookieWizardTests, 16 16 WizardTestKwargs, 17 17 WizardTestGenericViewInterface, 18 WizardModelTests, 18 19 )