Thursday, 15 April 2010

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



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

i'm using form wizard in django 1.4 conditionally add together instances of 7 models. regardless of steps user completes, i'd lastly step show preview of info entered. doesn't have form since user can utilize "first step" or "previous step" buttons go , prepare info messed up. i'd send confirmation email user info , suspect whatever solution come here provide info well.

here's have:

# views.py forms = [ ('person_application', personapplicationform), ('family_application', familyapplicationform), ('student_application', studentapplicationform), ('spouse', spouseform), ('child', childformset), ('roommate', roommateformset), ('preview', form), # doing because think formwizard requires form subclass every step, 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()}) homecoming context # # triggering infinite loop or because python gets stuck @ 100+% cpu , won't stop when kill runserver # def get_form_initial(self, step): # if step == 'preview': # homecoming self.get_all_cleaned_data() # homecoming {} ... # 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'), )

as can see, @ point thought i'd seek utilize form preview, tried overriding wizardview.get_form_initial. wanted utilize wizardview.get_all_cleaned_data() provide info form's initial dict. however, mentioned in comment, caused python stuck , had find , kill process manually stop it.

so i'm thinking i'll override wizardview.get_context_data() send context variable template containing info user has entered (again, using get_all_cleaned_data()). however, going bit complicated couple reasons. since fields of models have same name going shadow each other, i'll have go , namespace model field names. seems unecessary, whatever. also, 2 of forms modelformsets, info them comes list of dictionaries. not big deal, it's going create parsing in template more difficult. question getting long might helpful see data, here's illustration of returned get_all_cleaned_data() (as gets sent template):

{'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''},

so, question is, on right track or there improve way this? example, might utilize formpreview subclass form 'preview' step , define formpreview.done() as

def done(self, request, cleaned_data): pass

so info gets passed along formwizard's final processing machinery (i.e. wizardview.done())?

i'd override get_template_name handle template show (assuming have special 1 'preview` step).

then i'd overload get_form, appending info each step instance variable.

finally, i'd overload get_context_data append instance variable templates context.

overloading get_form let's manipulate info before preview displayed.

django django-forms django-formwizard

No comments:

Post a Comment