2020-02-06 22:49:33 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-18 13:42:35 +00:00
|
|
|
|
2020-03-11 10:15:03 +00:00
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
|
|
|
from rest_framework.filters import SearchFilter
|
2020-02-17 13:08:40 +00:00
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
from api.viewsets import ReadProtectedModelViewSet
|
2020-02-07 16:02:07 +00:00
|
|
|
from .serializers import ActivityTypeSerializer, ActivitySerializer, GuestSerializer
|
2020-03-07 21:28:59 +00:00
|
|
|
from ..models import ActivityType, Activity, Guest
|
2020-02-17 13:08:40 +00:00
|
|
|
|
2020-02-06 22:49:33 +00:00
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
class ActivityTypeViewSet(ReadProtectedModelViewSet):
|
2020-02-06 23:29:04 +00:00
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `ActivityType` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/activity/type/
|
|
|
|
"""
|
2020-02-06 22:49:33 +00:00
|
|
|
queryset = ActivityType.objects.all()
|
|
|
|
serializer_class = ActivityTypeSerializer
|
2020-03-11 10:15:03 +00:00
|
|
|
filter_backends = [DjangoFilterBackend]
|
|
|
|
filterset_fields = ['name', 'can_invite', ]
|
2020-02-06 22:49:33 +00:00
|
|
|
|
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
class ActivityViewSet(ReadProtectedModelViewSet):
|
2020-02-06 23:29:04 +00:00
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `Activity` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/activity/activity/
|
|
|
|
"""
|
2020-02-06 22:49:33 +00:00
|
|
|
queryset = Activity.objects.all()
|
|
|
|
serializer_class = ActivitySerializer
|
2020-03-11 10:15:03 +00:00
|
|
|
filter_backends = [DjangoFilterBackend]
|
|
|
|
filterset_fields = ['name', 'description', 'activity_type', ]
|
2020-02-06 22:49:33 +00:00
|
|
|
|
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
class GuestViewSet(ReadProtectedModelViewSet):
|
2020-02-06 23:29:04 +00:00
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `Guest` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/activity/guest/
|
|
|
|
"""
|
2020-02-06 22:49:33 +00:00
|
|
|
queryset = Guest.objects.all()
|
2020-02-17 13:08:40 +00:00
|
|
|
serializer_class = GuestSerializer
|
2020-03-11 10:15:03 +00:00
|
|
|
filter_backends = [SearchFilter]
|
|
|
|
search_fields = ['$name', ]
|