From b05178da9a4f05087f05d8dac718305c5478fdf3 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 18 Jan 2021 10:41:29 +0100 Subject: [PATCH] beautifyed beautify_data() --- evapp/views.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/evapp/views.py b/evapp/views.py index 29864f1..26d74cd 100644 --- a/evapp/views.py +++ b/evapp/views.py @@ -81,10 +81,16 @@ 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]}) + # 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() \ + if isinstance(v,collections.abc.Hashable) \ + and v in TRANSPONDER_CHOICES}) + return data