From 2501bb08668d3954e719e58ceab3a2cf97b3db96 Mon Sep 17 00:00:00 2001 From: corsaronero Date: Mon, 21 Nov 2022 13:09:12 +0000 Subject: [PATCH] changed fields in Travel to required, changed saving of value of selfbuy_give_data when person wants to selfbuy to false --- input/forms.py | 12 ++++++++++++ input/static/dropdown/js/base.js | 8 ++++++-- input/views.py | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/input/forms.py b/input/forms.py index c3e8127..da386f8 100644 --- a/input/forms.py +++ b/input/forms.py @@ -56,11 +56,23 @@ class InternForm(FdbForm): class TravelForm(FdbForm): # TODO: add some javascript to show/hide other-field + + # this is the code, to change required to false if needed + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['project_name'].required = True + self.fields['transport'].required = True + self.fields['travelcost'].required = True + self.fields['checkin'].required = True + self.fields['checkout'].required = True + self.fields['hotel'].required = True + class Meta: model = Travel exclude = ('granted', 'granted_date', 'survey_mail_send', 'realname', 'email', 'survey_mail_date', 'project', 'request_url', 'payed_for_hotel_by', 'payed_for_travel_by', 'intern_notes' ) widgets = {'checkin': AdminDateWidget(), 'checkout': AdminDateWidget(),} + fields = ['project_name', 'transport', 'travelcost', 'checkin', 'checkout', 'hotel', 'notes'] class LibraryForm(FdbForm): diff --git a/input/static/dropdown/js/base.js b/input/static/dropdown/js/base.js index 0d8d5c4..df0ae5f 100644 --- a/input/static/dropdown/js/base.js +++ b/input/static/dropdown/js/base.js @@ -1,10 +1,16 @@ window.addEventListener("load", function() { (function($) { $(function() { + + + // selfbuy section + var selectField_selfbuy = $('#id_selfbuy'), verified_selfbuy_div = $('#id_selfbuy_give_data').parent().parent(), verified_selfbuy = $('#id_selfbuy_give_data'); + + // make checked to get through the required function toggleVerified_selfbuy(value) { if (value === "FALSE") { verified_selfbuy_div.show(); @@ -23,8 +29,6 @@ window.addEventListener("load", function() { toggleVerified_selfbuy($(this).val()); }); - - var selectField = $('#id_variant'), verified = $('#id_url_of_pic').parent().parent(); diff --git a/input/views.py b/input/views.py index dd9fb4f..3ca0f33 100644 --- a/input/views.py +++ b/input/views.py @@ -202,8 +202,11 @@ class ExternView(CookieWizardView): data = {} for form in form_list: data = {**data, **form.cleaned_data} + + if data['selfbuy'] == 'TRUE': + data['selfbuy_give_data'] = 'False' print(data) - + # write data to database modell = form.save(commit=False) # we have to copy the data from the first form here @@ -214,6 +217,7 @@ class ExternView(CookieWizardView): # write type of form in some cases if data['choice'] in ('BIB', 'ELIT', 'SOFT'): modell.type = data['choice'] + form.save() # add some data to context for mail templates