1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-27 10:53:02 +00:00
nk20/apps/activity/api/views.py

46 lines
1.6 KiB
Python
Raw Normal View History

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-11 10:15:03 +00:00
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter
from api.viewsets import ReadProtectedModelViewSet
2020-03-20 01:14:43 +00:00
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-06 22:49:33 +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
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
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()
serializer_class = GuestSerializer
2020-03-11 10:15:03 +00:00
filter_backends = [SearchFilter]
search_fields = ['$name', ]