How can I show a preview of all the data entered as the final step of the django form wizard?

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:

# views.py
FORMS = [
    ('person_application',  PersonApplicationForm),
    ('family_application',  FamilyApplicationForm),
    ('student_application', StudentApplicationForm),
    ('spouse',              SpouseForm),
    ('child',               ChildFormSet),
    ('roommate',            RoommateFormSet),
    ('preview',             Form), # only doing this because I think FormWizard requires a Form subclass for every step, which makes sense
]

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

    # # This is triggering an infinite loop or something because python gets stuck at 100+% cpu and won't stop even when I kill runserver
    # def get_form_initial(self, step):
    #     if step == 'preview':
    #         return self.get_all_cleaned_data()
    #     return {}

    ...

# urls.py
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())?

+5
1

get_template_name, , ( ).

get_form, .

, get_context_data, .

get_form .

+1

All Articles