Skip to content

Commit cf9d7e0

Browse files
EncryptExAdriMM26
andauthored
Added diet disclaimer checkbox (#309)
* Add check diet on confirmation * Added conditional flow to diet notice --------- Co-authored-by: AdriMM26 <[email protected]>
1 parent 89427d2 commit cf9d7e0

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

applications/forms/base.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,16 @@ class ConfirmationInvitationForm(BootstrapFormMixin, forms.ModelForm):
145145
'fields': [{'name': 'tshirt_size', 'space': 4}, {'name': 'diet', 'space': 4},
146146
{'name': 'other_diet', 'space': 4},
147147
{'name': 'reimb', 'space': 12}, {'name': 'reimb_amount', 'space': 12},
148-
{'name': 'terms_and_conditions', 'space': 12}, {'name': 'mlh_required_terms', 'space': 12},
149-
{'name': 'mlh_required_privacy', 'space': 12}, {'name': 'mlh_subscribe', 'space': 12}
148+
{'name': 'terms_and_conditions', 'space': 12},
149+
{'name': 'mlh_required_terms', 'space': 12},
150+
{'name': 'mlh_required_privacy', 'space': 12}, {'name': 'mlh_subscribe', 'space': 12},
151+
{'name': 'diet_notice', 'space': 12}
150152
],
151153
},
152154
}
153155

154156
diet = forms.ChoiceField(label='Dietary requirements', choices=models.DIETS, required=True)
157+
155158
reimb = forms.TypedChoiceField(
156159
required=False,
157160
label='Do you need a travel reimbursement to attend?',
@@ -174,6 +177,12 @@ class ConfirmationInvitationForm(BootstrapFormMixin, forms.ModelForm):
174177
"Organizer Newsletters and other communications from MLH."
175178
)
176179

180+
diet_notice = forms.BooleanField(
181+
required=False,
182+
label='I authorize "Hackers at UPC" to use my food allergies and intolerances information to '
183+
'manage the catering service only.<span style="color: red; font-weight: bold;"> *</span>'
184+
)
185+
177186
mlh_required_privacy = forms.BooleanField(
178187
label="I authorize you to share my application/registration information with Major League Hacking for "
179188
"event administration, ranking, and MLH administration in-line with the MLH "
@@ -224,6 +233,19 @@ def clean_mlh_optional_communications(self):
224233
)
225234
return cc
226235

236+
237+
def clean_diet_notice(self):
238+
diet = self.cleaned_data.get('diet', 'None')
239+
diet_notice = self.cleaned_data.get('diet_notice', False)
240+
# Check that if it's the first submission hackers checks terms and conditions checkbox
241+
# self.instance.pk is None if there's no Application existing before
242+
# https://stackoverflow.com/questions/9704067/test-if-django-modelform-has-instance
243+
if diet != 'None' and not diet_notice and not self.instance.pk:
244+
raise forms.ValidationError(
245+
"In order to apply and attend you have to accept us to use your personal data related to your food "
246+
"allergies and intolerances only in order to manage the catering service."
247+
)
248+
return diet_notice
227249
def clean_other_diet(self):
228250
data = self.cleaned_data.get('other_diet', '')
229251
diet = self.cleaned_data.get('diet', 'None')

applications/templates/dashboard.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ <h3>When to leave</h3>
156156
conditional_field(other_diet, diet, function () {
157157
return diet.val() === 'Others';
158158
}, 1);
159+
160+
diet_notice = $('#id_diet_notice');
161+
conditional_field(diet_notice, diet, function () {
162+
return diet.val() !== 'None';
163+
}, 1);
164+
165+
function checkDietNotice(){
166+
if(diet.val() !== 'None'){
167+
diet_notice.parent().parent().parent().addClass('required');
168+
diet_notice.attr('required', 'true');
169+
}else{
170+
diet_notice.removeAttr('required');
171+
diet_notice.parent().parent().parent().removeClass('required');
172+
}
173+
}
174+
checkDietNotice();
175+
diet.on('change', function () {
176+
checkDietNotice();
177+
});
178+
159179
let needs_reimb = $('input[name="reimb"][value="True"]');
160180
let no_reimb = $('input[name="reimb"][value="False"]');
161181
let reimb_amout = $('#id_reimb_amount');

0 commit comments

Comments
 (0)