From 58924235ff62b812302cb4028c702c2deab9937f Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 19 Oct 2020 13:54:57 +0200 Subject: [PATCH] conditional labels in second form --- input/models.py | 8 +++++--- input/views.py | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/input/models.py b/input/models.py index b7d0ef1..29cc7f5 100644 --- a/input/models.py +++ b/input/models.py @@ -40,10 +40,12 @@ class Grant(Volunteer): abstract = True # same model is used for Library, ELitStip and Software! +TYPE_CHOICES = [('BIB', 'Bibliotheksstipendium'), + ('ELIT', 'eLiteraturstipendium'), + ('SOFT', 'Softwarestipendium')] + class Library(Grant): - TYPE_CHOICES = [('LIB', 'Bibliotheksstipendium'), - ('ELIT', 'eLiteraturstipendium'), - ('SOFT', 'Softwarestipendium')] + type = models.CharField( max_length=4, choices=TYPE_CHOICES, diff --git a/input/views.py b/input/views.py index 51ad60c..99a77e9 100644 --- a/input/views.py +++ b/input/views.py @@ -8,7 +8,7 @@ from django.template.loader import get_template from django.template import Context from .forms import ProjectForm, VolunteerForm, LibraryForm, IFGForm -from .models import Project +from .models import Project, TYPE_CHOICES def project(request): # return HttpResponse("Hello, world. You're at the input form") @@ -68,7 +68,11 @@ 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 else: print('ERROR! UNKNOWN FORMTYPE!') else: @@ -91,6 +95,7 @@ class ExternView(CookieWizardView): form.realname = data['realname'] form.username = data['username'] form.email = data['email'] + # write type of form in some cases if data['choice'] in ('BIB', 'ELIT', 'SOFT'): form.type = data['choice'] form.save()