From 93d1f2f9d5321f0dcd2fb0fa496240413efff277 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Wed, 21 Oct 2020 10:24:18 +0200 Subject: [PATCH] More Work on InternView. Basic HonoraryCertificate works --- input/views.py | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/input/views.py b/input/views.py index 2b11577..1b5234e 100644 --- a/input/views.py +++ b/input/views.py @@ -75,7 +75,45 @@ class InternView(CookieWizardView): '''This View is for the WMDE-employees only''' template_name = 'input/extern.html' - form_list = [InternForm, HonoraryCertificateForm] + form_list = [InternForm, ProjectForm] + + def get_form(self, step=None, data=None, files=None): + if step is None: + step = self.steps.current + print ("get_form() step " + step) + + if step == '1': + prev_data = self.get_cleaned_data_for_step('0') + choice = prev_data.get('choice') + if choice == 'HON': + print ('Ehrenamtsbescheinigung detected!') + form = HonoraryCertificateForm(data) + else: + print('ERROR! UNKNOWN FORMTYPE!') + else: + form = super().get_form(step, data, files) + return form + + def done(self, form_list, **kwargs): + print('ExternView.done() reached') + # gather data from all forms + data = {} + for form in form_list: + data = {**data, **form.cleaned_data} + print(data) + + # write data to database + form = form.save(commit=False) + # we have to copy the data from the first form here + # this is ugly code. how can we copy this without explicit writing? + # i found no way to access the ModelForm.Meta.exclude-tupel + form.realname = data['realname'] + form.username = data['username'] + form.email = data['email'] + form.save() + + return done(self.request) + class ExternView(CookieWizardView): '''This View is for Volunteers''' @@ -158,6 +196,3 @@ class ExternView(CookieWizardView): return HttpResponse('Invalid header found.') return done(self.request) - # return render(self.request, 'saved', { - # 'form_data': [form.cleaned_data for form in form_list], - # })