1
0
Fork 0

changed TYPE_CHOICES to dict to simplify some code

This commit is contained in:
Benni Bärmann 2020-10-21 13:27:05 +02:00
parent 74eacb26c5
commit 9e0903ca0e
3 changed files with 11 additions and 14 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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: