chol
/
eva
forked from tohe/eva
1
0
Fork 0

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
{% 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 %}
</p>
</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 %}
{{ key }}: {{ value }}<p>
{% endfor %}
@ -53,9 +53,9 @@
<form action="" method="post">
{% csrf_token %}
<table>
{% 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 }}

View File

@ -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')
]

View File

@ -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):