Skip to content

Commit

Permalink
Added diet disclaimer checkbox (#309)
Browse files Browse the repository at this point in the history
* Add check diet on confirmation

* Added conditional flow to diet notice

---------

Co-authored-by: AdriMM26 <adria.martinez@hackupc.com>
  • Loading branch information
EncryptEx and AdriMM26 authored Mar 13, 2024
1 parent 89427d2 commit cf9d7e0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
26 changes: 24 additions & 2 deletions applications/forms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ class ConfirmationInvitationForm(BootstrapFormMixin, forms.ModelForm):
'fields': [{'name': 'tshirt_size', 'space': 4}, {'name': 'diet', 'space': 4},
{'name': 'other_diet', 'space': 4},
{'name': 'reimb', 'space': 12}, {'name': 'reimb_amount', 'space': 12},
{'name': 'terms_and_conditions', 'space': 12}, {'name': 'mlh_required_terms', 'space': 12},
{'name': 'mlh_required_privacy', 'space': 12}, {'name': 'mlh_subscribe', 'space': 12}
{'name': 'terms_and_conditions', 'space': 12},
{'name': 'mlh_required_terms', 'space': 12},
{'name': 'mlh_required_privacy', 'space': 12}, {'name': 'mlh_subscribe', 'space': 12},
{'name': 'diet_notice', 'space': 12}
],
},
}

diet = forms.ChoiceField(label='Dietary requirements', choices=models.DIETS, required=True)

reimb = forms.TypedChoiceField(
required=False,
label='Do you need a travel reimbursement to attend?',
Expand All @@ -174,6 +177,12 @@ class ConfirmationInvitationForm(BootstrapFormMixin, forms.ModelForm):
"Organizer Newsletters and other communications from MLH."
)

diet_notice = forms.BooleanField(
required=False,
label='I authorize "Hackers at UPC" to use my food allergies and intolerances information to '
'manage the catering service only.<span style="color: red; font-weight: bold;"> *</span>'
)

mlh_required_privacy = forms.BooleanField(
label="I authorize you to share my application/registration information with Major League Hacking for "
"event administration, ranking, and MLH administration in-line with the MLH "
Expand Down Expand Up @@ -224,6 +233,19 @@ def clean_mlh_optional_communications(self):
)
return cc


def clean_diet_notice(self):
diet = self.cleaned_data.get('diet', 'None')
diet_notice = self.cleaned_data.get('diet_notice', False)
# Check that if it's the first submission hackers checks terms and conditions checkbox
# self.instance.pk is None if there's no Application existing before
# https://stackoverflow.com/questions/9704067/test-if-django-modelform-has-instance
if diet != 'None' and not diet_notice and not self.instance.pk:
raise forms.ValidationError(
"In order to apply and attend you have to accept us to use your personal data related to your food "
"allergies and intolerances only in order to manage the catering service."
)
return diet_notice
def clean_other_diet(self):
data = self.cleaned_data.get('other_diet', '')
diet = self.cleaned_data.get('diet', 'None')
Expand Down
20 changes: 20 additions & 0 deletions applications/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ <h3>When to leave</h3>
conditional_field(other_diet, diet, function () {
return diet.val() === 'Others';
}, 1);

diet_notice = $('#id_diet_notice');
conditional_field(diet_notice, diet, function () {
return diet.val() !== 'None';
}, 1);

function checkDietNotice(){
if(diet.val() !== 'None'){
diet_notice.parent().parent().parent().addClass('required');
diet_notice.attr('required', 'true');
}else{
diet_notice.removeAttr('required');
diet_notice.parent().parent().parent().removeClass('required');
}
}
checkDietNotice();
diet.on('change', function () {
checkDietNotice();
});

let needs_reimb = $('input[name="reimb"][value="True"]');
let no_reimb = $('input[name="reimb"][value="False"]');
let reimb_amout = $('#id_reimb_amount');
Expand Down

0 comments on commit cf9d7e0

Please sign in to comment.