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

editorial code cleanup

This commit is contained in:
Benni Bärmann 2021-02-04 12:30:46 +01:00
parent 17a52a46dc
commit ab80f8c352
1 changed files with 23 additions and 49 deletions

View File

@ -19,10 +19,8 @@ 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}")
'''this method is called via urls.py to determine if a form is part of the IN-Process'''
data = wizard.get_cleaned_data_for_step('0') or {}
print(data)
if data.get('choice') != 'CHANGE':
@ -35,14 +33,9 @@ def long_process(wizard):
return False
def change_process(wizard):
''' this method is called via urls.py to determine if the form is part of the change process'''
print('CHANGE PROZESS')
return not long_process(wizard)
# elif step < 3:
# return True
# elif step == 4:
# return True
# else:
# return False
class EvaFormView(CookieWizardView):
@ -56,30 +49,37 @@ class EvaFormView(CookieWizardView):
def set_choice(self, c):
self.choice = c
# this deletes data which is only used temporary and is not in the modell
def get_all_cleaned_data(self):
'''this method deletes data which is only used temporary and is not in the modell'''
data = super().get_all_cleaned_data()
print("delete CHOICE FROM DATA")
if 'choice' in data:
del data['choice']
return data
# we need this to display all the data in the last step
def get_context_data(self, form, **kwargs):
print('GETCONTEXT')
'''this method is called to give context data to the template'''
#print('GETCONTEXT')
context = super().get_context_data(form=form, **kwargs)
context.update({'choice': self.choice})
if (self.steps.current == 5 or (self.choice == 'CHANGE' and self.steps.current ==3)):
context.update({'data': self.beautify_data(self.get_all_cleaned_data())})
return context
#this makes shure, that we use the same model instance for all steps
def get_form_instance(self,step):
''' this method makes shure, that we use the same model instance for all steps'''
if self.instance == None:
self.instance = Employee()
return self.instance
def done(self, form_list, **kwargs):
'''this method is called from CookieWizardView after all forms are filled'''
print ('INSTANCE_DICT')
print(self.instance_dict)
@ -92,36 +92,7 @@ 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
# send a mail to the department with all needed data
def send_mail_to_department(self, department):
'send a mail to the given department with the nececcary notifications'
@ -150,13 +121,16 @@ class EvaFormView(CookieWizardView):
self.instance.delete()
return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!')
# use long form for contextdata instead of short form if available
#
# ATTENTION!
# This implementation works only for unique keys over all of these dicts from model.py
#
def beautify_data(self, data):
print("BEAUTIFY")
''' # use long form for contextdata instead of short form if available
#
# ATTENTION!
# This implementation works only for unique keys over all of these dicts from model.py
#
'''
# print("BEAUTIFY")
# update values in data dictionary with keys from *_CHOICES if present there
choices = {**DEPARTMENT_CHOICES, **LAPTOP_CHOICES, **TRANSPONDER_CHOICES,
**OS_CHOICES, **MOBILE_CHOICES, **LANG_CHOICES,}