Skip to content

Commit 045e118

Browse files
necessary129kriti21
authored andcommitted
Disallows max volunteer field to be edited with invalid number
Fixes #392
1 parent bff53c3 commit 045e118

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

vms/shift/views.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,11 @@ def form_valid(self, form):
345345
shift_date = form.cleaned_data['date']
346346
shift_start_time = form.cleaned_data['start_time']
347347
shift_end_time = form.cleaned_data['end_time']
348+
max_vols = form.cleaned_data['max_volunteers']
348349

349350
# save when all conditions satisfied
350-
if (shift_date >= start_date_job and shift_date <= end_date_job and shift_end_time > shift_start_time):
351+
if (shift_date >= start_date_job and shift_date <= end_date_job and shift_end_time > shift_start_time \
352+
and max_vols >= len(shift.volunteers.all())):
351353
shift_to_edit = form.save(commit=False)
352354
shift_to_edit.job = job
353355
shift_to_edit.save()
@@ -357,6 +359,9 @@ def form_valid(self, form):
357359
messages.add_message(self.request, messages.INFO, 'Shift date should lie within Job dates')
358360
if shift_end_time <= shift_start_time:
359361
messages.add_message(self.request, messages.INFO, 'Shift end time should be greater than start time')
362+
if max_vols < len(shift.volunteers.all()):
363+
messages.add_message(self.request, messages.INFO, 'Max volunteers should be greater than or equal to'
364+
' the already assigned volunteers.')
360365
return render(
361366
self.request,
362367
'shift/edit.html',

0 commit comments

Comments
 (0)