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-03-18 13:42:35 +00:00
|
|
|
from api.viewsets import ReadProtectedModelViewSet
|
2020-03-20 01:14:43 +00:00
|
|
|
|
2020-03-28 12:38:31 +00:00
|
|
|
from .serializers import ActivityTypeSerializer, ActivitySerializer, GuestSerializer, EntrySerializer
|
|
|
|
from ..models import ActivityType, Activity, Guest, Entry
|
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]
|
2020-03-28 00:45:13 +00:00
|
|
|
search_fields = ['$last_name', '$first_name', '$inviter__alias__name', '$inviter__alias__normalized_name', ]
|
2020-03-28 12:38:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EntryViewSet(ReadProtectedModelViewSet):
|
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `Entry` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/activity/entry/
|
|
|
|
"""
|
|
|
|
queryset = Entry.objects.all()
|
|
|
|
serializer_class = EntrySerializer
|
|
|
|
filter_backends = [SearchFilter]
|
|
|
|
search_fields = ['$last_name', '$first_name', '$inviter__alias__name', '$inviter__alias__normalized_name', ]
|