From 2d1ac9b8c60e0ed92b263ae695a4899058e6be80 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Thu, 21 Jan 2021 12:55:33 +0100 Subject: [PATCH] get_form() finally working (kind of) --- evapp/forms.py | 2 +- evapp/views.py | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/evapp/forms.py b/evapp/forms.py index 68b1d16..bddbcff 100644 --- a/evapp/forms.py +++ b/evapp/forms.py @@ -27,7 +27,7 @@ class PersonalForm(FdbForm): class Meta: model = Employee - fields = ['firstname', 'lastname', 'email', 'department', 'team',] + fields = ['firstname', 'lastname', 'email', 'department', 'team', ] class WorkingForm(FdbForm): class Meta: diff --git a/evapp/views.py b/evapp/views.py index c8c0b5f..74bbc13 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -26,7 +26,8 @@ class EvaFormView(CookieWizardView): # we need this to display all the data in the last step def get_context_data(self, form, **kwargs): context = super().get_context_data(form=form, **kwargs) - context.update({'data': self.beautify_data(self.get_all_cleaned_data())}) + if (self.steps.current == 5): + context.update({'data': self.beautify_data(self.get_all_cleaned_data())}) return context #this makes shure, that we use the same model instance for all steps @@ -48,6 +49,33 @@ class EvaFormView(CookieWizardView): self.send_mail_to_department(dep) return HttpResponseRedirect('success') + def get_form(self, step=None, data=None, files=None): + '''this function determines which process aut of E/V/A we will do''' + + if step is None: + step = self.steps.current + print ("get_form() step " + step) + + form = super().get_form(step, data, files) + + if step == '2': # why do we need step 2 here not 1???! + prev_data = self.get_cleaned_data_for_step('0') + choice = prev_data.get('choice') + print(f'choice detection: {INTERN_CHOICES[choice]}') + if choice == 'CHANGE': + print("process choosen: CHANGE") + form = WorkingForm(data) + elif choice == 'OUT': + print("process choosen: OUT") + form = WorkingForm(data) + elif choice == 'IN': + print("process choosen: IN") + form = WorkingForm(data) + else: + raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in EvaFormView') + + return form + # send a mail to the department with all needed data def send_mail_to_department(self, department): 'send a mail to the given department with the nececcary notifications' @@ -95,7 +123,6 @@ class EvaFormView(CookieWizardView): if 'accounts' in data: data['accounts'] = [ACCOUNT_CHOICES[c] for c in data['accounts']] - # replace keys in data dictionary with verbose_name newdata = {self.instance._meta.get_field(k).verbose_name.title() : v for k,v in data.items()}