mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-28 18:32:20 +00:00
58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
from api.viewsets import ReadProtectedModelViewSet
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
|
from rest_framework.filters import SearchFilter
|
|
|
|
from .serializers import ActivitySerializer, ActivityTypeSerializer, EntrySerializer, GuestSerializer
|
|
from ..models import Activity, ActivityType, Entry, Guest
|
|
|
|
|
|
class ActivityTypeViewSet(ReadProtectedModelViewSet):
|
|
"""
|
|
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/
|
|
"""
|
|
queryset = ActivityType.objects.all()
|
|
serializer_class = ActivityTypeSerializer
|
|
filter_backends = [DjangoFilterBackend]
|
|
filterset_fields = ['name', 'can_invite', ]
|
|
|
|
|
|
class ActivityViewSet(ReadProtectedModelViewSet):
|
|
"""
|
|
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/
|
|
"""
|
|
queryset = Activity.objects.all()
|
|
serializer_class = ActivitySerializer
|
|
filter_backends = [DjangoFilterBackend]
|
|
filterset_fields = ['name', 'description', 'activity_type', ]
|
|
|
|
|
|
class GuestViewSet(ReadProtectedModelViewSet):
|
|
"""
|
|
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/
|
|
"""
|
|
queryset = Guest.objects.all()
|
|
serializer_class = GuestSerializer
|
|
filter_backends = [SearchFilter]
|
|
search_fields = ['$last_name', '$first_name', '$inviter__alias__name', '$inviter__alias__normalized_name', ]
|
|
|
|
|
|
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', ]
|