From 3a3b7f25cbed4a7b2c2b09cbe75dfe0e52e9aef6 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Thu, 14 Jan 2021 12:44:04 +0100 Subject: [PATCH] fixed context data in last step --- evapp/templates/evapp/dataloop.txt | 1 + evapp/templates/evapp/employee_form.html | 6 +++++- evapp/views.py | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/evapp/templates/evapp/dataloop.txt b/evapp/templates/evapp/dataloop.txt index a47b40e..6f016a4 100644 --- a/evapp/templates/evapp/dataloop.txt +++ b/evapp/templates/evapp/dataloop.txt @@ -1,3 +1,4 @@ +dataloop {% for key, value in data.items %} {{ key }}: {{ value }} {% endfor %} diff --git a/evapp/templates/evapp/employee_form.html b/evapp/templates/evapp/employee_form.html index e11b076..3ec09f9 100644 --- a/evapp/templates/evapp/employee_form.html +++ b/evapp/templates/evapp/employee_form.html @@ -45,7 +45,11 @@ {% endif %}

- + {% if wizard.steps.step1 == 5 %} + {% for key, value in data.items %} + {{ key }}: {{ value }}

+ {% endfor %} + {% endif %}

{% csrf_token %} diff --git a/evapp/views.py b/evapp/views.py index 48bab61..2c02b96 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -49,10 +49,18 @@ class EvaFormView(CookieWizardView): template_name = 'evapp/employee_form.html' form_list = [PersonalForm, WorkingForm, ITForm, OfficeForm, DummyForm] instance = None + data = {} # form_class = EmployeeForm - def get_success_url(self): - return reverse('success') + def get_context_data(self, form, **kwargs): + context = super().get_context_data(form=form, **kwargs) + # self.data.update(form.cleaned_data) + # if self.steps.current == '5': + context.update({'data': self.get_all_cleaned_data()}) + return context + + # def get_success_url(self): + # return reverse('success') #this makes shure, that we use the same model instance for all steps def get_form_instance(self,step): @@ -66,10 +74,10 @@ class EvaFormView(CookieWizardView): print(self.instance_dict) for form in form_list: form.save() - form_data = [form.cleaned_data for form in form_list] - print(form_data) + # form_data = [form.cleaned_data for form in form_list] + # print(form_data) for dep in MAILS: - send_mail_to_department(dep, form_data) + send_mail_to_department(dep, self.get_all_cleaned_data()) return HttpResponseRedirect('success') # return super().form_valid(form)