Inscription en perm
This commit is contained in:
parent
634c4ad4ff
commit
6d81735a55
10 changed files with 105 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
from django.views.generic import TemplateView
|
||||
from django.views.generic import DetailView
|
||||
from django.views.generic import TemplateView, DetailView, View
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from django.http import JsonResponse, HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import Event, Activity
|
||||
from equipment.models import EquipmentAttribution
|
||||
|
@ -34,3 +36,22 @@ class ActivityView(LoginRequiredMixin, DetailView):
|
|||
.filter(activity=activity)
|
||||
.prefetch_related('equipment'))
|
||||
return context
|
||||
|
||||
|
||||
class EnrolActivityView(LoginRequiredMixin, View):
|
||||
http_method_names = ['post']
|
||||
|
||||
def post(self, request, pk, *args, **kwargs):
|
||||
activity = get_object_or_404(Activity, id=pk)
|
||||
action = request.POST.get("goal", None)
|
||||
success = True
|
||||
if action == "enrol":
|
||||
activity.staff.add(request.user)
|
||||
elif action == "unenrol":
|
||||
activity.staff.remove(request.user)
|
||||
else:
|
||||
success = False
|
||||
if "ajax" in request.GET:
|
||||
return render(request, "event/activity_summary.html",
|
||||
{"activity": activity})
|
||||
return HttpResponseRedirect(reverse("event:activity", kwargs={"pk":pk}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue