mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-25 07:02:22 +00:00
Add API filters for registration
This commit is contained in:
parent
1df1766753
commit
4f9dfadb71
@ -20,6 +20,10 @@ if "participation" in settings.INSTALLED_APPS:
|
|||||||
from participation.api.urls import register_participation_urls
|
from participation.api.urls import register_participation_urls
|
||||||
register_participation_urls(router, "participation")
|
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'
|
app_name = 'api'
|
||||||
|
|
||||||
# Wire up our API using automatic URL routing.
|
# Wire up our API using automatic URL routing.
|
||||||
|
2
apps/registration/api/__init__.py
Normal file
2
apps/registration/api/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
47
apps/registration/api/serializers.py
Normal file
47
apps/registration/api/serializers.py
Normal 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,
|
||||||
|
}
|
11
apps/registration/api/urls.py
Normal file
11
apps/registration/api/urls.py
Normal 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)
|
15
apps/registration/api/views.py
Normal file
15
apps/registration/api/views.py
Normal 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', ]
|
@ -19,7 +19,7 @@ phonenumbers~=8.9.10
|
|||||||
psycopg2-binary~=2.8
|
psycopg2-binary~=2.8
|
||||||
PyPDF3~=1.0.2
|
PyPDF3~=1.0.2
|
||||||
ipython~=7.19.0
|
ipython~=7.19.0
|
||||||
python-magic>=0.4.21
|
python-magic>=0.4.22
|
||||||
requests~=2.25.0
|
requests~=2.25.0
|
||||||
sympasoap~=1.0
|
sympasoap~=1.0
|
||||||
whoosh~=2.7
|
whoosh~=2.7
|
Loading…
Reference in New Issue
Block a user