On Feb 2, 2009, at 23:32, [email protected] wrote:
> On Feb 1, 2:38 am, "[email protected]" <[email protected]>
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---