diff --git a/Back-End/Subscriptions/urls.py b/Back-End/Subscriptions/urls.py index b71a3e7..f1044d3 100644 --- a/Back-End/Subscriptions/urls.py +++ b/Back-End/Subscriptions/urls.py @@ -19,7 +19,8 @@ from .views import ( AbsenceManagementListCreateView, AbsenceManagementDetailView, StudentCompetencyListCreateView, - StudentCompetencySimpleView + StudentCompetencySimpleView, + search_students ) from .views import RegistrationFileGroupView, RegistrationFileGroupSimpleView, get_registration_files_by_group @@ -38,6 +39,7 @@ urlpatterns = [ re_path(r'^students$', StudentListView.as_view(), name="students"), # Page de formulaire d'inscription - ELEVE re_path(r'^students/(?P[0-9]+)$', StudentView.as_view(), name="students"), + re_path(r'^search-students', search_students, name='search_students'), # Page PARENT - Liste des children re_path(r'^children/(?P[0-9]+)$', ChildrenListView.as_view(), name="children"), diff --git a/Back-End/Subscriptions/views/__init__.py b/Back-End/Subscriptions/views/__init__.py index 549b3e0..abab71c 100644 --- a/Back-End/Subscriptions/views/__init__.py +++ b/Back-End/Subscriptions/views/__init__.py @@ -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' ] diff --git a/Back-End/Subscriptions/views/student_views.py b/Back-End/Subscriptions/views/student_views.py index 0db929e..fcacaf1 100644 --- a/Back-End/Subscriptions/views/student_views.py +++ b/Back-End/Subscriptions/views/student_views.py @@ -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) \ No newline at end of file diff --git a/Front-End/src/app/[locale]/admin/grades/page.js b/Front-End/src/app/[locale]/admin/grades/page.js index a833527..b290ed7 100644 --- a/Front-End/src/app/[locale]/admin/grades/page.js +++ b/Front-End/src/app/[locale]/admin/grades/page.js @@ -16,9 +16,11 @@ import { useRouter } from 'next/navigation'; import { fetchStudents, fetchStudentCompetencies, + searchStudents, } from '@/app/actions/subscriptionAction'; import { useEstablishment } from '@/context/EstablishmentContext'; import { useClasses } from '@/context/ClassesContext'; +import StudentInput from '@/components/Grades/StudentInput'; export default function Page() { const router = useRouter(); @@ -147,7 +149,19 @@ export default function Page() {

Sélectionner un élève

- s.id === formData.selectedStudent) || null + } + setSelectedStudent={(student) => + handleChange('selectedStudent', student?.id || '') + } + searchStudents={searchStudents} + establishmentId={selectedEstablishmentId} + required + /> + {/* handleChange('selectedStudent', e.target.value)} choices={students.map((student) => ({ value: student.id, - label: `${student.last_name} ${student.first_name} - ${getNiveauLabel(student.level)} (${student.associated_class_name})`, + label: `${student.last_name} ${student.first_name} - ${getNiveauLabel( + student.level + )} (${student.associated_class_name})`, }))} required - /> + /> */}