Commit f856dd47 authored by Stefano Rivera's avatar Stefano Rivera

Add some error messages around volunteering

parent 04702003
from django.views.generic import FormView, DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import UpdateView
from django.contrib import messages
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import F, Q
from django.http import HttpResponseForbidden
......@@ -100,13 +101,21 @@ class TaskView(DetailView):
for task in self.object.concurrent_tasks()
for volunteer in task.volunteers.all()]
# TODO Show an error message
if self.object in volunteer.tasks.all():
volunteer.tasks.remove(self.object)
self.object.volunteers.remove(volunteer)
elif (self.object.nbr_volunteers < self.object.max_volunteers) and (volunteer not in concurrent_volunteers):
messages.info(request, 'Removed')
elif volunteer in concurrent_volunteers:
# TODO Show where the user is going to be
messages.error(request,
'You are already volunteering in this time-slot. '
'You can only be in one place at a time.')
elif self.object.nbr_volunteers >= self.object.max_volunteers:
messages.error(request, 'This task already has enough volunteers.')
else:
volunteer.tasks.add(self.object)
self.object.volunteers.add(volunteer)
messages.success(request, 'Thank you for volunteering!')
return redirect('wafer_task', pk=self.object.pk)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment