Add API filters for registration

This commit is contained in:
Yohann D'ANELLO 2021-03-29 16:24:58 +02:00
parent 1df1766753
commit 4f9dfadb71
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
6 changed files with 80 additions and 1 deletions

View File

@ -20,6 +20,10 @@ if "participation" in settings.INSTALLED_APPS:
from participation.api.urls import register_participation_urls
register_participation_urls(router, "participation")
if "registration" in settings.INSTALLED_APPS:
from registration.api.urls import register_registration_urls
register_registration_urls(router, "registration")
app_name = 'api'
# Wire up our API using automatic URL routing.

View File

@ -0,0 +1,2 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later

View File

@ -0,0 +1,47 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from rest_framework import serializers
from rest_polymorphic.serializers import PolymorphicSerializer
from ..models import AdminRegistration, CoachRegistration, ParticipantRegistration, \
StudentRegistration, VolunteerRegistration
class AdminSerializer(serializers.ModelSerializer):
class Meta:
model = AdminRegistration
fields = '__all__'
class CoachSerializer(serializers.ModelSerializer):
class Meta:
model = CoachRegistration
fields = '__all__'
class ParticipantSerializer(serializers.ModelSerializer):
class Meta:
model = ParticipantRegistration
fields = '__all__'
class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = StudentRegistration
fields = '__all__'
class VolunteerSerializer(serializers.ModelSerializer):
class Meta:
model = VolunteerRegistration
fields = '__all__'
class RegistrationSerializer(PolymorphicSerializer):
model_serializer_mapping = {
AdminRegistration: AdminSerializer,
CoachRegistration: CoachSerializer,
StudentRegistration: StudentSerializer,
VolunteerRegistration: VolunteerSerializer,
}

View File

@ -0,0 +1,11 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from .views import RegistrationViewSet
def register_registration_urls(router, path):
"""
Configure router for registration REST API.
"""
router.register(path + "/registration", RegistrationViewSet)

View File

@ -0,0 +1,15 @@
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.viewsets import ModelViewSet
from .serializers import RegistrationSerializer
from ..models import Registration
class RegistrationViewSet(ModelViewSet):
queryset = Registration.objects.all()
serializer_class = RegistrationSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ['user', 'participantregistration__team', ]

View File

@ -19,7 +19,7 @@ phonenumbers~=8.9.10
psycopg2-binary~=2.8
PyPDF3~=1.0.2
ipython~=7.19.0
python-magic>=0.4.21
python-magic>=0.4.22
requests~=2.25.0
sympasoap~=1.0
whoosh~=2.7