1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00
nk20/apps/activity/api/views.py

58 lines
2.2 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
from api.viewsets import ReadProtectedModelViewSet
2020-03-11 10:15:03 +00:00
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.filters import SearchFilter
2020-03-20 01:14:43 +00:00
from .serializers import ActivitySerializer, ActivityTypeSerializer, EntrySerializer, GuestSerializer
from ..models import Activity, ActivityType, Entry, 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]
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', ]