mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-04 04:01:27 +00:00
feat: Ajout d'un système de notation par classe et par matière et par élève [N3WTS-6]
This commit is contained in:
@ -16,7 +16,9 @@ from .models import (
|
||||
PaymentPlan,
|
||||
PaymentMode,
|
||||
EstablishmentCompetency,
|
||||
Competency
|
||||
Competency,
|
||||
Evaluation,
|
||||
StudentEvaluation
|
||||
)
|
||||
from .serializers import (
|
||||
TeacherSerializer,
|
||||
@ -28,7 +30,9 @@ from .serializers import (
|
||||
PaymentPlanSerializer,
|
||||
PaymentModeSerializer,
|
||||
EstablishmentCompetencySerializer,
|
||||
CompetencySerializer
|
||||
CompetencySerializer,
|
||||
EvaluationSerializer,
|
||||
StudentEvaluationSerializer
|
||||
)
|
||||
from Common.models import Domain, Category
|
||||
from N3wtSchool.bdd import delete_object, getAllObjects, getObject
|
||||
@ -785,3 +789,179 @@ class EstablishmentCompetencyDetailView(APIView):
|
||||
return JsonResponse({'message': 'Deleted'}, safe=False)
|
||||
except EstablishmentCompetency.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
# ===================== EVALUATIONS =====================
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class EvaluationListCreateView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request):
|
||||
establishment_id = request.GET.get('establishment_id')
|
||||
school_class_id = request.GET.get('school_class')
|
||||
period = request.GET.get('period')
|
||||
|
||||
if not establishment_id:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
evaluations = Evaluation.objects.filter(establishment_id=establishment_id)
|
||||
|
||||
if school_class_id:
|
||||
evaluations = evaluations.filter(school_class_id=school_class_id)
|
||||
if period:
|
||||
evaluations = evaluations.filter(period=period)
|
||||
|
||||
serializer = EvaluationSerializer(evaluations, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
data = JSONParser().parse(request)
|
||||
serializer = EvaluationSerializer(data=data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return JsonResponse(serializer.data, safe=False, status=status.HTTP_201_CREATED)
|
||||
return JsonResponse(serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class EvaluationDetailView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, id):
|
||||
try:
|
||||
evaluation = Evaluation.objects.get(id=id)
|
||||
serializer = EvaluationSerializer(evaluation)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
except Evaluation.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
def put(self, request, id):
|
||||
try:
|
||||
evaluation = Evaluation.objects.get(id=id)
|
||||
except Evaluation.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
data = JSONParser().parse(request)
|
||||
serializer = EvaluationSerializer(evaluation, data=data, partial=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
return JsonResponse(serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def delete(self, request, id):
|
||||
try:
|
||||
evaluation = Evaluation.objects.get(id=id)
|
||||
evaluation.delete()
|
||||
return JsonResponse({'message': 'Deleted'}, safe=False)
|
||||
except Evaluation.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
# ===================== STUDENT EVALUATIONS =====================
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class StudentEvaluationListView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request):
|
||||
student_id = request.GET.get('student_id')
|
||||
evaluation_id = request.GET.get('evaluation_id')
|
||||
period = request.GET.get('period')
|
||||
school_class_id = request.GET.get('school_class_id')
|
||||
|
||||
student_evals = StudentEvaluation.objects.all()
|
||||
|
||||
if student_id:
|
||||
student_evals = student_evals.filter(student_id=student_id)
|
||||
if evaluation_id:
|
||||
student_evals = student_evals.filter(evaluation_id=evaluation_id)
|
||||
if period:
|
||||
student_evals = student_evals.filter(evaluation__period=period)
|
||||
if school_class_id:
|
||||
student_evals = student_evals.filter(evaluation__school_class_id=school_class_id)
|
||||
|
||||
serializer = StudentEvaluationSerializer(student_evals, many=True)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class StudentEvaluationBulkUpdateView(APIView):
|
||||
"""
|
||||
Mise à jour en masse des notes des élèves pour une évaluation.
|
||||
Attendu dans le body :
|
||||
[
|
||||
{ "student_id": 1, "evaluation_id": 1, "score": 15.5, "comment": "", "is_absent": false },
|
||||
...
|
||||
]
|
||||
"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def put(self, request):
|
||||
data = JSONParser().parse(request)
|
||||
if not isinstance(data, list):
|
||||
data = [data]
|
||||
|
||||
updated = []
|
||||
errors = []
|
||||
|
||||
for item in data:
|
||||
student_id = item.get('student_id')
|
||||
evaluation_id = item.get('evaluation_id')
|
||||
|
||||
if not student_id or not evaluation_id:
|
||||
errors.append({'error': 'student_id et evaluation_id sont requis', 'item': item})
|
||||
continue
|
||||
|
||||
try:
|
||||
student_eval, created = StudentEvaluation.objects.update_or_create(
|
||||
student_id=student_id,
|
||||
evaluation_id=evaluation_id,
|
||||
defaults={
|
||||
'score': item.get('score'),
|
||||
'comment': item.get('comment', ''),
|
||||
'is_absent': item.get('is_absent', False)
|
||||
}
|
||||
)
|
||||
updated.append(StudentEvaluationSerializer(student_eval).data)
|
||||
except Exception as e:
|
||||
errors.append({'error': str(e), 'item': item})
|
||||
|
||||
return JsonResponse({'updated': updated, 'errors': errors}, safe=False)
|
||||
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class StudentEvaluationDetailView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get(self, request, id):
|
||||
try:
|
||||
student_eval = StudentEvaluation.objects.get(id=id)
|
||||
serializer = StudentEvaluationSerializer(student_eval)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
except StudentEvaluation.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
def put(self, request, id):
|
||||
try:
|
||||
student_eval = StudentEvaluation.objects.get(id=id)
|
||||
except StudentEvaluation.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
data = JSONParser().parse(request)
|
||||
serializer = StudentEvaluationSerializer(student_eval, data=data, partial=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
return JsonResponse(serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def delete(self, request, id):
|
||||
try:
|
||||
student_eval = StudentEvaluation.objects.get(id=id)
|
||||
student_eval.delete()
|
||||
return JsonResponse({'message': 'Deleted'}, safe=False)
|
||||
except StudentEvaluation.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
Reference in New Issue
Block a user