From 3f9a84a3f2f679caccf92fff80a44fb8dabe9631 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Wed, 3 Feb 2021 10:53:02 +0100 Subject: [PATCH] complete new conditional forms handling with condition_dict (still only partially working) --- evapp/templates/evapp/employee_form.html | 14 ++--- evapp/urls.py | 7 ++- evapp/views.py | 77 +++++++++++++++--------- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/evapp/templates/evapp/employee_form.html b/evapp/templates/evapp/employee_form.html index 6ec00b7..78a29b6 100644 --- a/evapp/templates/evapp/employee_form.html +++ b/evapp/templates/evapp/employee_form.html @@ -36,16 +36,16 @@ Angaben zur Person {% elif wizard.steps.step1 == 2 %} Angaben zum neuen Arbeitsverhältnis - {% elif wizard.steps.step1 == 3 %} + {% elif wizard.steps.step1 == 3 and choice == 'IN' %} IT-relevante Angaben - {% elif wizard.steps.step1 == 4 %} + {% elif wizard.steps.step1 == 4 and choice == 'IN' %} Office-relevante Angaben - {% elif wizard.steps.step1 == 5 %} + {% else %} Bestätigungsschritt {% endif %}

- {% if wizard.steps.step1 == 5 or choice == 'CHANGE' and wizards.steps.step1 == 3 %} + {% if wizard.steps.step1 == 3 and choice == 'CHANGE' or wizards.steps.step1 == 5 %} {% for key, value in data.items %} {{ key }}: {{ value }}

{% endfor %} @@ -53,9 +53,9 @@

{% csrf_token %} - {% if choice %} - Du hast {{choice}} ausgewählt. - {% endif %} + {% if choice %} + Du hast {{choice}} ausgewählt. + {% endif %} {{ wizard.management_form }} {% if wizard.form.forms %} {{ wizard.form.management_form }} diff --git a/evapp/urls.py b/evapp/urls.py index 021ef20..740a5f2 100644 --- a/evapp/urls.py +++ b/evapp/urls.py @@ -1,8 +1,11 @@ from django.urls import path -from .views import EvaFormView, success +from .views import EvaFormView, success, long_process urlpatterns = [ - path('', EvaFormView.as_view(), name='evaform'), + path('', EvaFormView.as_view(condition_dict = {'2': long_process, + '3': long_process,}), + #'4': long_process,}), + name='evaform'), path('success', success, name='success') ] diff --git a/evapp/views.py b/evapp/views.py index 08643d5..a3b7b06 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -18,6 +18,26 @@ from .settings import MAILS, EVA_MAIL, BASIC_DATA def success(request): return HttpResponse("Vielen Dank! Du hast E.V.A. erfolgreich ausgefüllt. Die Mails an die Abteilungen wurden versendet.") +def long_process(wizard): + # step = wizard.steps.step0 + # if step == 0: + # return True + #print(f"gathering data for step {step}") + data = wizard.get_cleaned_data_for_step('0') or {} + print(data) + if data.get('choice') == 'IN': + print('PROZESS IN') + return True + else: + print('PROZESS NOT IN') + return False + # elif step < 3: + # return True + # elif step == 4: + # return True + # else: + # return False + class EvaFormView(CookieWizardView): template_name = 'evapp/employee_form.html' @@ -25,6 +45,7 @@ class EvaFormView(CookieWizardView): instance = None choice = 'IN' + # this deletes data which is only used temporary and is not in the modell def get_all_cleaned_data(self): data = super().get_all_cleaned_data() del data['choice'] @@ -57,34 +78,34 @@ 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 == '1': # 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: {TYPE_CHOICES[choice]}') - self.choice = choice - if choice == 'CHANGE': - print("process choosen: CHANGE") - form = ChangeForm(data) - # self.form_list = [PersonalForm, ChangeForm, DummyForm,] - 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 + # 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 == '1': # 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: {TYPE_CHOICES[choice]}') + # self.choice = choice + # if choice == 'CHANGE': + # print("process choosen: CHANGE") + # form = ChangeForm(data) + # # self.form_list = [PersonalForm, ChangeForm, DummyForm,] + # 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):