From 9e0903ca0e7f4cec3c710b187b2308422a3bdf43 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Wed, 21 Oct 2020 13:27:05 +0200 Subject: [PATCH] changed TYPE_CHOICES to dict to simplify some code --- input/forms.py | 2 +- input/models.py | 18 +++++++++--------- input/views.py | 5 +---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/input/forms.py b/input/forms.py index f692a25..990e1e5 100644 --- a/input/forms.py +++ b/input/forms.py @@ -17,7 +17,7 @@ class ProjectForm(ModelForm): class VolunteerForm(ModelForm): - choice = ChoiceField(choices=TYPE_CHOICES, widget=RadioSelect, + choice = ChoiceField(choices=TYPE_CHOICES.items(), widget=RadioSelect, label='Was möchtest Du beantragen?') check = BooleanField(required=True, diff --git a/input/models.py b/input/models.py index 624e2dc..2f504ee 100644 --- a/input/models.py +++ b/input/models.py @@ -49,21 +49,21 @@ class Grant(Volunteer): abstract = True -TYPE_CHOICES = [('BIB', 'Bibliotheksstipendium'), - ('ELIT', 'eLiteraturstipendium'), - ('SOFT', 'Softwarestipendium'), - ('VIS', 'Visitenkarten'), - ('LIST', 'Mailingliste'), - ('MAIL', 'E-Mail-Adresse'), - ('IFG', 'Kostenübernahme IFG-Anfrage'), - ('LIT', 'Literaturstipendium'),] +TYPE_CHOICES = {'BIB': 'Bibliotheksstipendium', + 'ELIT': 'eLiteraturstipendium', + 'SOFT': 'Softwarestipendium', + 'VIS': 'Visitenkarten', + 'LIST': 'Mailingliste', + 'MAIL': 'E-Mail-Adresse', + 'IFG': 'Kostenübernahme IFG-Anfrage', + 'LIT': 'Literaturstipendium',} # same model is used for Library, ELitStip and Software! class Library(Grant): type = models.CharField( max_length=4, - choices=TYPE_CHOICES, #attention: actually only BIB, ELIT, SOFT should be used here + choices=TYPE_CHOICES.items(), #attention: actually only BIB, ELIT, SOFT should be used here default='LIB', ) library = models.CharField(max_length=200) diff --git a/input/views.py b/input/views.py index fbaf0f7..dfac4f2 100644 --- a/input/views.py +++ b/input/views.py @@ -106,11 +106,8 @@ class ExternView(CookieWizardView): form = IFGForm(data) elif choice in ('BIB', 'SOFT', 'ELIT'): print ('one of the famous three detected!') - for (k,v) in TYPE_CHOICES: - if k == choice: - break form = LibraryForm(data) - form.fields['library'].label = v + form.fields['library'].label = TYPE_CHOICES[choice] else: raise RuntimeError(f'ERROR! UNKNOWN FORMTYPE {choice}') else: