FormWizard accessing previous fields data
Hi all, say i have a FormWizard of 5 steps and at the last step i want to display a summary of the submitted data how do i access the value of a field that was in the form at step 1? example: class Step1(Form): foo = CharField() bar = CharField() So at step 5 i'd like to display the value of Step1.foo. Thanks, Lorenzo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FormWizard accessing previous fields data
On Jan 29, 11:31 pm, "lbologn...@gmail.com" wrote: > Hi all, > > say i have aFormWizardof 5 steps and at the last step i want to > display a summary of the submitted data how do i access the value of a > field that was in the form at step 1? Maybe i didn't express myself well enough. My problem is accessing previous steps fields in the template. Something like a classic {{form.foo}} doesn't work because previous fields are passed on to the next step as raw html and they're all contained in {{form.previous_fields}} My wizard is like 5 steps and on step 1 the user is asked firstname and lastname on a form. At step 5 i want to display a summary of submitted info like: Fistname: John Lastname: Doe but i can't simply do {{form.firstname}} Thanks, Lorenzo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FormWizard accessing previous fields data
On Feb 1, 3:27 am, "lbologn...@gmail.com" wrote: > On Jan 29, 11:31 pm, "lbologn...@gmail.com" > wrote: > > > Hi all, > > > say i have aFormWizardof 5 steps and at the last step i want to > > display a summary of the submitted data how do i access the value of a > > field that was in the form at step 1? > > Maybe i didn't express myself well enough. > > My problem is accessing previous steps fields in the template. > Something like a classic {{form.foo}} doesn't work because previous > fields are passed on to the next step as raw html and they're all > contained in {{form.previous_fields}} > > My wizard is like 5 steps and on step 1 the user is asked firstname > and lastname on a form. At step 5 i want to display a summary of > submitted info like: > > Fistname: John > Lastname: Doe > > but i can't simply do {{form.firstname}} > > Thanks, > Lorenzo I never understood the logic of it either. I also expected to be able to do something like {{ previous_fields.firstname }}. regards Matthew -- http://wadofstuff.blogspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FormWizard accessing previous fields data
On Feb 1, 2:38 am, "mattimust...@gmail.com" wrote: > I never understood the logic of it either. I also expected to be able > to do something like {{previous_fields.firstname }}. Found it! class EnrollWizard(FormWizard): def get_template(self, step): return 'enroll_wizard_%s.html' % step def process_step(self, request, form, current_step): if current_step == 3: form0 = self.get_form(0, request.POST) form1 = self.get_form(1, request.POST) form2 = self.get_form(2, request.POST) context = (dict(form0=form0, form1=form1, form2=form2)) return render_to_response(self.get_template(self.step), context) And then in the template to display a summary i play with ifequal {%ifequal form0.course 2%} Intensive course {%endif%} {%ifequal form0.course 1%} Standard course {%endif%} If anybody has a more elegant solution i'm all ears! Thanks, Lorenzo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FormWizard accessing previous fields data
On Feb 2, 2009, at 23:32, lbologn...@gmail.com wrote: > On Feb 1, 2:38 am, "mattimust...@gmail.com" > wrote: > >> I never understood the logic of it either. I also expected to be able >> to do something like {{previous_fields.firstname }}. > > Found it! > > class EnrollWizard(FormWizard): > >def get_template(self, step): >return 'enroll_wizard_%s.html' % step > >def process_step(self, request, form, current_step): > >if current_step == 3: >form0 = self.get_form(0, request.POST) >form1 = self.get_form(1, request.POST) >form2 = self.get_form(2, request.POST) > >context = (dict(form0=form0, form1=form1, form2=form2)) > >return render_to_response(self.get_template(self.step), > context) > > And then in the template to display a summary i play with ifequal > > {%ifequal form0.course 2%} > Intensive course > {%endif%} > > {%ifequal form0.course 1%} > Standard course > {%endif%} > > If anybody has a more elegant solution i'm all ears! Not sure whether it is more elegant or not, but here goes: As I understand it, the wizard-class contains an extra_context that automatically gets handed to the templates. You can modify the extra_context in the process_step-method, allowing you to add additional information for each step you go through. Also, as I understand it, the process_step-method is given a cleaned (correct) form for the current step, so you can extract information from that form and put it into the extra_context. Thus, you could do something like (no changes to get_template): class EnrollWizard(FormWizard): def process_step(self, request, form, step): if step == 0: self.extra_context['foo'] = form.cleaned_data['foo'] elif step == 1: self.extra_context['bar'] = form.cleaned_data['bar'] elif step == 3: self.extra_context['baz'] = form.cleaned_data['baz'] Now, in each template you will have access to more and more additional information, just like so: {{ foo }} {{ bar }} {{ baz }} I am not sure exactly how this maps to your example (as I do not fully understand it), but maybe it could simplify things slightly for you? Now, if someone could point me to a simple way of combining form wizards with formsets, my day would be complete... :-) Cheers, johan -- Johan Liseborn --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: FormWizard accessing previous fields data
On Feb 3, 12:17 am, Johan Liseborn wrote: > Thus, you could do something like (no changes to get_template): > > class EnrollWizard(FormWizard): > def process_step(self, request, form, step): > if step == 0: > self.extra_context['foo'] = form.cleaned_data['foo'] > elif step == 1: > self.extra_context['bar'] = form.cleaned_data['bar'] > elif step == 3: > self.extra_context['baz'] = form.cleaned_data['baz'] > > Now, in each template you will have access to more and more additional > information, just like so: > > {{ foo }} Good solution, i like it! Thanks, Lorenzo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---