mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Champ de recherche de l'élève [#16]
This commit is contained in:
@ -10,7 +10,7 @@ from .registration_file_views import (
|
||||
RegistrationParentFileTemplateView
|
||||
)
|
||||
from .registration_file_group_views import RegistrationFileGroupView, RegistrationFileGroupSimpleView, get_registration_files_by_group
|
||||
from .student_views import StudentView, StudentListView, ChildrenListView
|
||||
from .student_views import StudentView, StudentListView, ChildrenListView, search_students
|
||||
from .guardian_views import GuardianView, DissociateGuardianView
|
||||
from .absences_views import AbsenceManagementDetailView, AbsenceManagementListCreateView
|
||||
from .student_competencies_views import StudentCompetencyListCreateView, StudentCompetencySimpleView
|
||||
@ -42,5 +42,6 @@ __all__ = [
|
||||
'AbsenceManagementDetailView',
|
||||
'AbsenceManagementListCreateView',
|
||||
'StudentCompetencyListCreateView',
|
||||
'StudentCompetencySimpleView'
|
||||
'StudentCompetencySimpleView',
|
||||
'search_students'
|
||||
]
|
||||
|
||||
@ -3,6 +3,7 @@ from rest_framework.views import APIView
|
||||
from rest_framework import status
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
from django.db.models import Q
|
||||
|
||||
from Subscriptions.serializers import StudentByRFCreationSerializer, RegistrationFormByParentSerializer, StudentSerializer
|
||||
from Subscriptions.models import Student, RegistrationForm
|
||||
@ -115,3 +116,37 @@ class ChildrenListView(APIView):
|
||||
).distinct()
|
||||
students_serializer = RegistrationFormByParentSerializer(students, many=True)
|
||||
return JsonResponse(students_serializer.data, safe=False)
|
||||
|
||||
def search_students(request):
|
||||
"""
|
||||
API pour rechercher des étudiants en fonction d'un terme de recherche (nom/prénom) et d'un établissement.
|
||||
"""
|
||||
query = request.GET.get('q', '').strip()
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
|
||||
if not query:
|
||||
return JsonResponse([], safe=False)
|
||||
|
||||
if not establishment_id:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# Recherche sur Student (nom ou prénom) et filtrage par établissement via RegistrationForm
|
||||
students = Student.objects.filter(
|
||||
Q(last_name__icontains=query) | Q(first_name__icontains=query),
|
||||
registrationform__establishment_id=establishment_id
|
||||
).distinct()
|
||||
|
||||
# Sérialisation simple (adapte selon ton besoin)
|
||||
results = [
|
||||
{
|
||||
'id': student.id,
|
||||
'first_name': student.first_name,
|
||||
'last_name': student.last_name,
|
||||
'level': getattr(student.level, 'name', ''),
|
||||
'associated_class_name': student.associated_class.atmosphere_name if student.associated_class else '',
|
||||
'photo': student.photo.url if student.photo else None,
|
||||
}
|
||||
for student in students
|
||||
]
|
||||
|
||||
return JsonResponse(results, safe=False)
|
||||
Reference in New Issue
Block a user