complete new conditional forms handling with condition_dict (still only partially working)

This commit is contained in:
Benni Bärmann 2021-02-03 10:53:02 +01:00
parent 3f92e323bf
commit 3f9a84a3f2
3 changed files with 61 additions and 37 deletions

View File

@ -36,16 +36,16 @@
Angaben zur Person Angaben zur Person
{% elif wizard.steps.step1 == 2 %} {% elif wizard.steps.step1 == 2 %}
Angaben zum neuen Arbeitsverhältnis Angaben zum neuen Arbeitsverhältnis
{% elif wizard.steps.step1 == 3 %} {% elif wizard.steps.step1 == 3 and choice == 'IN' %}
IT-relevante Angaben IT-relevante Angaben
{% elif wizard.steps.step1 == 4 %} {% elif wizard.steps.step1 == 4 and choice == 'IN' %}
Office-relevante Angaben Office-relevante Angaben
{% elif wizard.steps.step1 == 5 %} {% else %}
Bestätigungsschritt Bestätigungsschritt
{% endif %} {% endif %}
</p> </p>
</h2> </h2>
{% 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 %} {% for key, value in data.items %}
{{ key }}: {{ value }}<p> {{ key }}: {{ value }}<p>
{% endfor %} {% endfor %}
@ -53,9 +53,9 @@
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
<table> <table>
{% if choice %} {% if choice %}
Du hast {{choice}} ausgewählt. Du hast {{choice}} ausgewählt.
{% endif %} {% endif %}
{{ wizard.management_form }} {{ wizard.management_form }}
{% if wizard.form.forms %} {% if wizard.form.forms %}
{{ wizard.form.management_form }} {{ wizard.form.management_form }}

View File

@ -1,8 +1,11 @@
from django.urls import path from django.urls import path
from .views import EvaFormView, success from .views import EvaFormView, success, long_process
urlpatterns = [ 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') path('success', success, name='success')
] ]

View File

@ -18,6 +18,26 @@ from .settings import MAILS, EVA_MAIL, BASIC_DATA
def success(request): def success(request):
return HttpResponse("Vielen Dank! Du hast E.V.A. erfolgreich ausgefüllt. Die Mails an die Abteilungen wurden versendet.") 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): class EvaFormView(CookieWizardView):
template_name = 'evapp/employee_form.html' template_name = 'evapp/employee_form.html'
@ -25,6 +45,7 @@ class EvaFormView(CookieWizardView):
instance = None instance = None
choice = 'IN' choice = 'IN'
# this deletes data which is only used temporary and is not in the modell
def get_all_cleaned_data(self): def get_all_cleaned_data(self):
data = super().get_all_cleaned_data() data = super().get_all_cleaned_data()
del data['choice'] del data['choice']
@ -57,34 +78,34 @@ class EvaFormView(CookieWizardView):
self.send_mail_to_department(dep) self.send_mail_to_department(dep)
return HttpResponseRedirect('success') return HttpResponseRedirect('success')
def get_form(self, step=None, data=None, files=None): # def get_form(self, step=None, data=None, files=None):
'''this function determines which process aut of E/V/A we will do''' # '''this function determines which process aut of E/V/A we will do'''
#
if step is None: # if step is None:
step = self.steps.current # step = self.steps.current
print ("get_form() step " + step) # print ("get_form() step " + step)
#
form = super().get_form(step, data, files) # form = super().get_form(step, data, files)
#
if step == '1': # why do we need step 2 here not 1???! # if step == '1': # why do we need step 2 here not 1???!
prev_data = self.get_cleaned_data_for_step('0') # prev_data = self.get_cleaned_data_for_step('0')
choice = prev_data.get('choice') # choice = prev_data.get('choice')
print(f'choice detection: {TYPE_CHOICES[choice]}') # print(f'choice detection: {TYPE_CHOICES[choice]}')
self.choice = choice # self.choice = choice
if choice == 'CHANGE': # if choice == 'CHANGE':
print("process choosen: CHANGE") # print("process choosen: CHANGE")
form = ChangeForm(data) # form = ChangeForm(data)
# self.form_list = [PersonalForm, ChangeForm, DummyForm,] # # self.form_list = [PersonalForm, ChangeForm, DummyForm,]
elif choice == 'OUT': # elif choice == 'OUT':
print("process choosen: OUT") # print("process choosen: OUT")
form = WorkingForm(data) # form = WorkingForm(data)
elif choice == 'IN': # elif choice == 'IN':
print("process choosen: IN") # print("process choosen: IN")
form = WorkingForm(data) # form = WorkingForm(data)
else: # else:
raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in EvaFormView') # raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice} in EvaFormView')
#
return form # return form
# send a mail to the department with all needed data # send a mail to the department with all needed data
def send_mail_to_department(self, department): def send_mail_to_department(self, department):