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

added ugly function to beautify data

This commit is contained in:
Benni Bärmann 2021-01-14 15:10:29 +01:00
parent ab261c6118
commit b6970cdf04
3 changed files with 42 additions and 5 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1.4 on 2021-01-14 13:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('evapp', '0002_auto_20201223_1223'),
]
operations = [
migrations.AlterField(
model_name='employee',
name='transponder',
field=models.CharField(choices=[('NORM', 'allgemeiner Transponder'), ('SPECIAL', 'besondere Schließungen (bitte angeben)'), ('NOTRANS', 'Kein Transponder')], default='NORM', max_length=7),
),
]

View File

@ -1,6 +1,10 @@
from django.db import models from django.db import models
from multiselectfield import MultiSelectField from multiselectfield import MultiSelectField
# ATTENTION!!!
# No key should be used twice in any of these dicts because of the
# implementation in views.EvaFormView.beautify_data()
#
DEPARTMENT_CHOICES = {'PROG': 'Programme', DEPARTMENT_CHOICES = {'PROG': 'Programme',
'SOFT': 'Softwareentwicklung', 'SOFT': 'Softwareentwicklung',
'CENT': 'Central', 'CENT': 'Central',
@ -32,7 +36,7 @@ ACCOUNT_CHOICES = {'OTRSWMDE': 'OTRS (WMDE)',
TRANSPONDER_CHOICES = {'NORM': 'allgemeiner Transponder', TRANSPONDER_CHOICES = {'NORM': 'allgemeiner Transponder',
'SPECIAL': 'besondere Schließungen (bitte angeben)', 'SPECIAL': 'besondere Schließungen (bitte angeben)',
'NO': 'Kein Transponder',} 'NOTRANS': 'Kein Transponder',}
class Employee(models.Model): class Employee(models.Model):
# personal data # personal data

View File

@ -1,4 +1,5 @@
from smtplib import SMTPException from smtplib import SMTPException
import collections
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView
from django.urls import reverse from django.urls import reverse
@ -8,7 +9,8 @@ from django.template.loader import get_template
from formtools.wizard.views import CookieWizardView from formtools.wizard.views import CookieWizardView
from django.shortcuts import render from django.shortcuts import render
from .models import Employee from .models import Employee, DEPARTMENT_CHOICES, LAPTOP_CHOICES, OS_CHOICES,\
MOBILE_CHOICES, LANG_CHOICES, ACCOUNT_CHOICES, TRANSPONDER_CHOICES
from .forms import PersonalForm, WorkingForm, ITForm, OfficeForm, DummyForm from .forms import PersonalForm, WorkingForm, ITForm, OfficeForm, DummyForm
from .settings import MAILS, EVA_MAIL from .settings import MAILS, EVA_MAIL
@ -20,12 +22,11 @@ class EvaFormView(CookieWizardView):
template_name = 'evapp/employee_form.html' template_name = 'evapp/employee_form.html'
form_list = [PersonalForm, WorkingForm, ITForm, OfficeForm, DummyForm] form_list = [PersonalForm, WorkingForm, ITForm, OfficeForm, DummyForm]
instance = None instance = None
# data = {}
# 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.get_all_cleaned_data()}) 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
@ -73,3 +74,17 @@ class EvaFormView(CookieWizardView):
except SMTPException: except SMTPException:
self.instance.delete() self.instance.delete()
return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!') 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):
for k, v in data.items():
# print(f"v: {v}")
if isinstance(v,collections.Hashable):
if v in TRANSPONDER_CHOICES.keys():
print(f"found {v} in TRANSPONDER_CHOICES")
data.update({k : TRANSPONDER_CHOICES[v]})
return data