mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Bilan de compétence d'un élève [#16]
This commit is contained in:
@ -325,7 +325,7 @@ class RegistrationSchoolFileTemplate(models.Model):
|
||||
class StudentCompetency(models.Model):
|
||||
student = models.ForeignKey('Subscriptions.Student', on_delete=models.CASCADE, related_name='competency_scores')
|
||||
competency = models.ForeignKey('Common.Competency', on_delete=models.CASCADE, related_name='student_scores')
|
||||
score = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
|
||||
score = models.IntegerField(null=True, blank=True)
|
||||
comment = models.TextField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
|
||||
@ -63,12 +63,36 @@ class StudentCompetencyListCreateView(APIView):
|
||||
"data": result
|
||||
}, safe=False, status=200)
|
||||
|
||||
# def post(self, request):
|
||||
# serializer = AbsenceManagementSerializer(data=request.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)
|
||||
def put(self, request):
|
||||
"""
|
||||
Met à jour en masse les notes des compétences d'un élève.
|
||||
Attend une liste d'objets {"competenceId": ..., "grade": ...}
|
||||
"""
|
||||
data = request.data
|
||||
if not isinstance(data, list):
|
||||
return JsonResponse({"error": "Une liste est attendue."}, status=400)
|
||||
updated = []
|
||||
errors = []
|
||||
for item in data:
|
||||
comp_id = item.get("competenceId")
|
||||
grade = item.get("grade")
|
||||
student_id = item.get('studentId')
|
||||
print(f'lecture des données : {comp_id} - {grade} - {student_id}')
|
||||
if comp_id is None or grade is None:
|
||||
errors.append({"competenceId": comp_id, "error": "champ manquant"})
|
||||
continue
|
||||
try:
|
||||
# Ajoute le filtre student_id
|
||||
sc = StudentCompetency.objects.get(
|
||||
competency_id=comp_id,
|
||||
student_id=student_id
|
||||
)
|
||||
sc.score = grade
|
||||
sc.save()
|
||||
updated.append(comp_id)
|
||||
except StudentCompetency.DoesNotExist:
|
||||
errors.append({"competenceId": comp_id, "error": "not found"})
|
||||
return JsonResponse({"updated": updated, "errors": errors}, status=200)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
|
||||
Reference in New Issue
Block a user