get_form() finally working (kind of)
This commit is contained in:
parent
5df881fa75
commit
2d1ac9b8c6
|
@ -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:
|
||||||
|
|
|
@ -26,6 +26,7 @@ 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)
|
||||||
|
if (self.steps.current == 5):
|
||||||
context.update({'data': self.beautify_data(self.get_all_cleaned_data())})
|
context.update({'data': self.beautify_data(self.get_all_cleaned_data())})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -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()}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue