Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions website/registrations/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def __init__(self, *args, **kwargs):
self.fields["project3"].queryset = Project.objects.filter(
semester=Semester.objects.get_first_semester_with_open_registration()
)
self.warnings = []

ignore_warnings = forms.BooleanField(
label="I acknowledge the warning(s) and want to proceed with the registration",
required=False,
initial=False,
)

github_id = forms.IntegerField(disabled=True, label="GitHub ID")
github_username = forms.CharField(disabled=True, label="GitHub Username")
Expand Down Expand Up @@ -280,4 +287,18 @@ def clean(self):

if len(set(filter(None, (project1, project2, project3)))) != 3:
raise ValidationError("You should fill in all preferences with unique values.")

available_slots = sum(
bool(cleaned_data.get(f"available_during_scheduled_timeslot_{i}"))
for i in range(1, 11)
)

if available_slots < 4 and not cleaned_data.get("available_during_scheduled_timeslot_10"):
warning = (
"You are only available for less than 4 scheduled timeslots and "
"not available for the last timeslot on Friday afternoon. "
"This may make scheduling difficult."
)
self.warnings.append(warning)

return cleaned_data
10 changes: 10 additions & 0 deletions website/registrations/templates/registrations/step-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ <h6>{{ registration_semester }}</h6>
<hr>
<form method="post" class="form">
{% csrf_token %}

{% if form.warnings %}

<p><small>Please check the box below to continue with registration</small></p>
{% else %}
<style>
#id_ignore_warnings { display: none; }
label[for="id_ignore_warnings"] { display: none; }
</style>
{% endif %}
{% bootstrap_form form %}
{% bootstrap_button "Submit" name="submit" value="submit" button_type="submit" button_class="btn-secondary" %}
</form>
Expand Down
6 changes: 5 additions & 1 deletion website/registrations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def get_initial(self):
return initial

def form_valid(self, form):
"""Check for warnings before registering."""
if form.warnings and not form.cleaned_data.get("ignore_warnings"):
form.add_error(None, form.warnings[0])
return self.form_invalid(form)

"""Register new user if the form is valid."""
with transaction.atomic():
user, _ = User.objects.get_or_create(github_id=self.request.session["github_id"])
Expand All @@ -91,7 +96,6 @@ def form_valid(self, form):
user.github_username = form.cleaned_data["github_username"]
user.student_number = form.cleaned_data["student_number"]
user.save()

Registration.objects.create(
user=user,
semester=Semester.objects.get_first_semester_with_open_registration(),
Expand Down
Loading