I use the form wizard in django 1.4 to conditionally add instances of up to seven models. No matter what steps the user has completed, I would like the last step to show a preview of all the data entered. It should not be a form, as the user can use the "First Step" or "Previous Step" buttons to return and correct any data that they messed up. I would also like to send a confirmation email to the user with all their data, and I suspect that any solution I came up with here will provide the data for this.
Here I have:
FORMS = [
('person_application', PersonApplicationForm),
('family_application', FamilyApplicationForm),
('student_application', StudentApplicationForm),
('spouse', SpouseForm),
('child', ChildFormSet),
('roommate', RoommateFormSet),
('preview', Form),
]
TEMPLATES = {
...
'preview': 'preview.html',
}
condition_dict = {
...
'preview': True,
}
class SignupWizard(SessionWizardView):
...
def get_context_data(self, form, **kwargs):
context = super(SignupWizard, self).get_context_data(form=form, **kwargs)
if self.steps.current == 'preview':
context.update({'all_data': self.get_all_cleaned_data()})
return context
...
urlpatterns = patterns('app.views',
...
url(r'^start$', SignupWizard.as_view(FORMS, condition_dict=condition_dict, instance_dict=modelform_instances), name='wizard'),
url(r'^thanks$', 'thanks', name='thanks'),
)
, - , Form , WizardView.get_form_initial. WizardView.get_all_cleaned_data(), initial dict. , , python , , .
, , WizardView.get_context_data(), , , ( , get_all_cleaned_data()). . , , , . , . , - ModelFormSets, . , . , , , get_all_cleaned_data() ( , ):
{'all_data': {'birthdate': datetime.date(1940, 2, 5),
'building_pref_1': u'NGH4',
'building_pref_2': u'K2',
'city': u'Nashville',
'country': u'',
'email': u'johnny@cash.com',
'first_name': u'Johnny',
u'formset-child': [{'birthdate': datetime.date(2013, 2, 3),
'gender': u'F',
'id': None,
'name': u'Rosanne'},
{'birthdate': datetime.date(2013, 2, 1),
'gender': u'F',
'id': None,
'name': u'Cathy'},
{'birthdate': datetime.date(2013, 2, 5),
'gender': u'F',
'id': None,
'name': u'Cindy'},
{'birthdate': datetime.date(2013, 2, 2),
'gender': u'F',
'id': None,
'name': u'Tara'},
{},
{}],
'furnishing': u'F',
'gender': u'F',
'global_id': u'',
'last_name': u'Cash',
'living_situation': u'SC',
'middle_initial': u'',
'move_in_date': None,
'move_out_date': None,
'name': u'Vivian Liberto',
'phone': u'9891111111',
'smoker_status': u'True',
'state_province': u'TN',
'street_1': u'street',
'street_2': u'',
'student_number': None,
'term': <Term: Summer 2013>,
'type': u'F',
'university_status': u'O',
'university_status_other': u'Travelling musician',
'zip_code': u''},
, : ? , FormPreview FormPreview.done()
def done(self, request, cleaned_data):
pass
FormWizard (.. WizardView.done())?