mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
@@ -1,9 +1,14 @@
|
||||
"""
|
||||
Views for displaying / manipulating models within the Activities app.
|
||||
"""
|
||||
from django.views.generic import DetailView, ListView
|
||||
import json
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import DetailView, ListView, View
|
||||
from django.views.generic.detail import SingleObjectMixin
|
||||
|
||||
from . import models
|
||||
from people import models as people_models
|
||||
|
||||
|
||||
class ActivitySeriesListView(ListView):
|
||||
@@ -38,3 +43,44 @@ class ActivityDetailView(DetailView):
|
||||
"""
|
||||
model = models.Activity
|
||||
template_name = 'activities/activity/detail.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context['user_is_attending'] = self.object.attendance_list.filter(pk=self.request.user.person.pk).exists()
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ActivityAttendanceView(SingleObjectMixin, View):
|
||||
"""
|
||||
View to add or delete attendance of an activity.
|
||||
"""
|
||||
model = models.Activity
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
if request.is_ajax():
|
||||
data = json.loads(request.body)
|
||||
|
||||
person = people_models.Person.objects.get(pk=data['pk'])
|
||||
self.object.attendance_list.add(person)
|
||||
|
||||
return HttpResponse(status=204)
|
||||
|
||||
pass
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
if request.is_ajax():
|
||||
data = json.loads(request.body)
|
||||
|
||||
person = people_models.Person.objects.get(pk=data['pk'])
|
||||
self.object.attendance_list.remove(person)
|
||||
|
||||
return HttpResponse(status=204)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user