2024-02-07 01:26:49 +00:00
|
|
|
# Copyright (C) 2018-2024 by BDE ENS Paris-Saclay
|
2020-02-06 22:44:59 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-12-22 01:54:11 +00:00
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
2022-03-10 15:11:01 +00:00
|
|
|
from rest_framework.filters import OrderingFilter
|
|
|
|
from api.filters import RegexSafeSearchFilter
|
2020-03-18 13:42:35 +00:00
|
|
|
from api.viewsets import ReadProtectedModelViewSet
|
2020-03-20 01:14:43 +00:00
|
|
|
|
2020-07-25 17:40:30 +00:00
|
|
|
from .serializers import ProfileSerializer, ClubSerializer, MembershipSerializer
|
|
|
|
from ..models import Profile, Club, Membership
|
2020-02-06 22:43:56 +00:00
|
|
|
|
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
class ProfileViewSet(ReadProtectedModelViewSet):
|
2020-02-06 23:29:04 +00:00
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `Profile` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/members/profile/
|
|
|
|
"""
|
2020-12-23 13:54:21 +00:00
|
|
|
queryset = Profile.objects.order_by('id')
|
2020-02-06 22:43:56 +00:00
|
|
|
serializer_class = ProfileSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-22 01:54:11 +00:00
|
|
|
filterset_fields = ['user', 'user__first_name', 'user__last_name', 'user__username', 'user__email',
|
|
|
|
'user__note__alias__name', 'user__note__alias__normalized_name', 'phone_number', "section",
|
|
|
|
'department', 'promotion', 'address', 'paid', 'ml_events_registration', 'ml_sport_registration',
|
|
|
|
'ml_art_registration', 'report_frequency', 'email_confirmed', 'registration_valid', ]
|
2020-12-23 13:54:21 +00:00
|
|
|
search_fields = ['$user__first_name', '$user__last_name', '$user__username', '$user__email',
|
2020-12-22 01:54:11 +00:00
|
|
|
'$user__note__alias__name', '$user__note__alias__normalized_name', ]
|
2020-02-06 22:43:56 +00:00
|
|
|
|
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
class ClubViewSet(ReadProtectedModelViewSet):
|
2020-02-06 23:29:04 +00:00
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `Club` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/members/club/
|
|
|
|
"""
|
2020-12-23 13:54:21 +00:00
|
|
|
queryset = Club.objects.order_by('id')
|
2020-02-06 22:43:56 +00:00
|
|
|
serializer_class = ClubSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, RegexSafeSearchFilter]
|
2020-12-22 01:54:11 +00:00
|
|
|
filterset_fields = ['name', 'email', 'note__alias__name', 'note__alias__normalized_name', 'parent_club',
|
|
|
|
'parent_club__name', 'require_memberships', 'membership_fee_paid', 'membership_fee_unpaid',
|
|
|
|
'membership_duration', 'membership_start', 'membership_end', ]
|
|
|
|
search_fields = ['$name', '$email', '$note__alias__name', '$note__alias__normalized_name', ]
|
2020-02-06 22:43:56 +00:00
|
|
|
|
|
|
|
|
2020-03-18 13:42:35 +00:00
|
|
|
class MembershipViewSet(ReadProtectedModelViewSet):
|
2020-02-06 23:29:04 +00:00
|
|
|
"""
|
|
|
|
REST API View set.
|
|
|
|
The djangorestframework plugin will get all `Membership` objects, serialize it to JSON with the given serializer,
|
|
|
|
then render it on /api/members/membership/
|
|
|
|
"""
|
2020-12-23 13:54:21 +00:00
|
|
|
queryset = Membership.objects.order_by('id')
|
2020-02-06 22:43:56 +00:00
|
|
|
serializer_class = MembershipSerializer
|
2022-03-10 15:11:01 +00:00
|
|
|
filter_backends = [DjangoFilterBackend, OrderingFilter, RegexSafeSearchFilter]
|
2020-12-22 01:54:11 +00:00
|
|
|
filterset_fields = ['club__name', 'club__email', 'club__note__alias__name', 'club__note__alias__normalized_name',
|
|
|
|
'user__username', 'user__last_name', 'user__first_name', 'user__email',
|
|
|
|
'user__note__alias__name', 'user__note__alias__normalized_name',
|
2020-12-22 11:42:54 +00:00
|
|
|
'date_start', 'date_end', 'fee', 'roles', ]
|
2020-12-22 01:54:11 +00:00
|
|
|
ordering_fields = ['id', 'date_start', 'date_end', ]
|
|
|
|
search_fields = ['$club__name', '$club__email', '$club__note__alias__name', '$club__note__alias__normalized_name',
|
|
|
|
'$user__username', '$user__last_name', '$user__first_name', '$user__email',
|
2020-12-22 11:42:54 +00:00
|
|
|
'$user__note__alias__name', '$user__note__alias__normalized_name', '$roles__name', ]
|