From 7154707e99c4dcb80bdb58cceafb5ae2a7ffcf06 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 18 Jan 2021 12:34:45 +0100 Subject: [PATCH] even more beauty in beautify_data() --- evapp/views.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/evapp/views.py b/evapp/views.py index 26d74cd..62de163 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -81,16 +81,12 @@ class EvaFormView(CookieWizardView): # 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]}) # update data with keys from *_CHOICES if present there - data.update({k:TRANSPONDER_CHOICES[v] for k,v in data.items() \ + choices = {**DEPARTMENT_CHOICES, **LAPTOP_CHOICES, **TRANSPONDER_CHOICES, + **OS_CHOICES, **MOBILE_CHOICES, **LANG_CHOICES,} + data.update({k:choices[v] for k,v in data.items() \ if isinstance(v,collections.abc.Hashable) \ - and v in TRANSPONDER_CHOICES}) + and v in choices}) return data