added ugly function to beautify data
This commit is contained in:
parent
ab261c6118
commit
b6970cdf04
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -1,6 +1,10 @@
|
|||
from django.db import models
|
||||
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',
|
||||
'SOFT': 'Softwareentwicklung',
|
||||
'CENT': 'Central',
|
||||
|
@ -32,7 +36,7 @@ ACCOUNT_CHOICES = {'OTRSWMDE': 'OTRS (WMDE)',
|
|||
|
||||
TRANSPONDER_CHOICES = {'NORM': 'allgemeiner Transponder',
|
||||
'SPECIAL': 'besondere Schließungen (bitte angeben)',
|
||||
'NO': 'Kein Transponder',}
|
||||
'NOTRANS': 'Kein Transponder',}
|
||||
|
||||
class Employee(models.Model):
|
||||
# personal data
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from smtplib import SMTPException
|
||||
import collections
|
||||
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.urls import reverse
|
||||
|
@ -8,7 +9,8 @@ from django.template.loader import get_template
|
|||
from formtools.wizard.views import CookieWizardView
|
||||
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 .settings import MAILS, EVA_MAIL
|
||||
|
||||
|
@ -20,12 +22,11 @@ class EvaFormView(CookieWizardView):
|
|||
template_name = 'evapp/employee_form.html'
|
||||
form_list = [PersonalForm, WorkingForm, ITForm, OfficeForm, DummyForm]
|
||||
instance = None
|
||||
# data = {}
|
||||
|
||||
# we need this to display all the data in the last step
|
||||
def get_context_data(self, 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
|
||||
|
||||
#this makes shure, that we use the same model instance for all steps
|
||||
|
@ -56,7 +57,7 @@ class EvaFormView(CookieWizardView):
|
|||
# only the relevant data should be in the context
|
||||
data = self.get_all_cleaned_data()
|
||||
newdata = {k: v for k, v in data.items() if (k in MAILS[department]['DATA'])}
|
||||
|
||||
|
||||
context = {'data': newdata}
|
||||
|
||||
try:
|
||||
|
@ -73,3 +74,17 @@ class EvaFormView(CookieWizardView):
|
|||
except SMTPException:
|
||||
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):
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue