4 from django
import forms
5 from django
.contrib
.auth
.models
import User
6 from django
.core
.files
.storage
import FileSystemStorage
7 from django
.forms
.formsets
import formset_factory
8 from django
.forms
.models
import modelformset_factory
9 from django
.http
import HttpResponse
10 from django
.template
import Template
, Context
12 from django
.contrib
.auth
.models
import User
14 from django
.contrib
.formtools
.wizard
.views
import WizardView
16 temp_storage_location
= tempfile
.mkdtemp(dir=os
.environ
.get('DJANGO_TEST_TEMP_DIR'))
17 temp_storage
= FileSystemStorage(location
=temp_storage_location
)
19 class Page1(forms
.Form
):
20 name
= forms
.CharField(max_length
=100)
21 user
= forms
.ModelChoiceField(queryset
=User
.objects
.all())
22 thirsty
= forms
.NullBooleanField()
24 class Page2(forms
.Form
):
25 address1
= forms
.CharField(max_length
=100)
26 address2
= forms
.CharField(max_length
=100)
27 file1
= forms
.FileField()
29 class Page3(forms
.Form
):
30 random_crap
= forms
.CharField(max_length
=100)
32 Page4
= formset_factory(Page3
, extra
=2)
34 class ContactWizard(WizardView
):
35 file_storage
= temp_storage
37 def done(self
, form_list
, **kwargs
):
39 'form_list': [x
.cleaned_data
for x
in form_list
],
40 'all_cleaned_data': self
.get_all_cleaned_data(),
43 for form
in self
.form_list
.keys():
44 c
[form
] = self
.get_cleaned_data_for_step(form
)
46 c
['this_will_fail'] = self
.get_cleaned_data_for_step('this_will_fail')
47 return HttpResponse(Template('').render(c
))
49 def get_context_data(self
, form
, **kwargs
):
50 context
= super(ContactWizard
, self
).get_context_data(form
, **kwargs
)
51 if self
.storage
.current_step
== 'form2':
52 context
.update({'another_var': True})
55 class UserForm(forms
.ModelForm
):
58 fields
= ('username', 'email')
60 UserFormSet
= modelformset_factory(User
, form
=UserForm
)
62 class SessionContactWizard(ContactWizard
):
63 storage_name
= 'django.contrib.formtools.wizard.storage.session.SessionStorage'
65 class CookieContactWizard(ContactWizard
):
66 storage_name
= 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'