WMDE
/
eva
forked from tohe/eva
7
1
Fork 0

get_form() finally working (kind of)

This commit is contained in:
Benni Bärmann 2021-01-21 12:55:33 +01:00
parent 5df881fa75
commit 2d1ac9b8c6
2 changed files with 30 additions and 3 deletions

View File

@ -27,7 +27,7 @@ class PersonalForm(FdbForm):
class Meta: class Meta:
model = Employee model = Employee
fields = ['firstname', 'lastname', 'email', 'department', 'team',] fields = ['firstname', 'lastname', 'email', 'department', 'team', ]
class WorkingForm(FdbForm): class WorkingForm(FdbForm):
class Meta: class Meta:

View File

@ -26,7 +26,8 @@ class EvaFormView(CookieWizardView):
# we need this to display all the data in the last step # we need this to display all the data in the last step
def get_context_data(self, form, **kwargs): def get_context_data(self, form, **kwargs):
context = super().get_context_data(form=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 return context
#this makes shure, that we use the same model instance for all steps #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) self.send_mail_to_department(dep)
return HttpResponseRedirect('success') 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 # send a mail to the department with all needed data
def send_mail_to_department(self, department): def send_mail_to_department(self, department):
'send a mail to the given department with the nececcary notifications' 'send a mail to the given department with the nececcary notifications'
@ -95,7 +123,6 @@ class EvaFormView(CookieWizardView):
if 'accounts' in data: if 'accounts' in data:
data['accounts'] = [ACCOUNT_CHOICES[c] for c in data['accounts']] data['accounts'] = [ACCOUNT_CHOICES[c] for c in data['accounts']]
# replace keys in data dictionary with verbose_name # 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()} newdata = {self.instance._meta.get_field(k).verbose_name.title() : v for k,v in data.items()}