diff --git a/Back-End/Subscriptions/templates/pdfs/bilan_competences.html b/Back-End/Subscriptions/templates/pdfs/bilan_competences.html
index 6e64148..529c8c4 100644
--- a/Back-End/Subscriptions/templates/pdfs/bilan_competences.html
+++ b/Back-End/Subscriptions/templates/pdfs/bilan_competences.html
@@ -44,7 +44,7 @@
{{ domaine.nom }} |
-
+
diff --git a/Back-End/Subscriptions/views/student_competencies_views.py b/Back-End/Subscriptions/views/student_competencies_views.py
index bbfa831..b803249 100644
--- a/Back-End/Subscriptions/views/student_competencies_views.py
+++ b/Back-End/Subscriptions/views/student_competencies_views.py
@@ -104,6 +104,7 @@ class StudentCompetencyListCreateView(APIView):
return JsonResponse({"error": "Une liste est attendue."}, status=400)
updated = []
errors = []
+ updated_competency_ids = set()
for item in data:
comp_id = item.get("competenceId")
grade = item.get("grade")
@@ -113,7 +114,6 @@ class StudentCompetencyListCreateView(APIView):
errors.append({"competenceId": comp_id, "error": "champ manquant"})
continue
try:
- # Ajoute le filtre student_id
sc = StudentCompetency.objects.get(
establishment_competency_id=comp_id,
student_id=student_id,
@@ -122,14 +122,19 @@ class StudentCompetencyListCreateView(APIView):
sc.score = grade
sc.save()
updated.append(comp_id)
+ updated_competency_ids.add(sc.id)
except StudentCompetency.DoesNotExist:
errors.append({"competenceId": comp_id, "error": "not found"})
# Génération du PDF si au moins une compétence a été mise à jour
if updated:
student = Student.objects.get(id=student_id)
- # Reconstituer la structure "domaines" pour la période concernée uniquement
- student_competencies = StudentCompetency.objects.filter(student=student, period=period).select_related(
+ # On ne prend que les StudentCompetency mis à jour pour la génération du PDF
+ student_competencies = StudentCompetency.objects.filter(
+ student=student,
+ period=period,
+ id__in=updated_competency_ids
+ ).select_related(
'establishment_competency',
'establishment_competency__competency',
'establishment_competency__competency__category',
@@ -137,6 +142,7 @@ class StudentCompetencyListCreateView(APIView):
'establishment_competency__custom_category',
'establishment_competency__custom_category__domain',
)
+
result = []
domaines = Domain.objects.all()
for domaine in domaines:
@@ -183,14 +189,10 @@ class StudentCompetencyListCreateView(APIView):
}
pdf_result = render_to_pdf('pdfs/bilan_competences.html', context)
-
try:
filename = f"bilan_competences_{student.last_name}_{student.first_name}_{period}.pdf"
- # Vérifier si un bilan existe déjà pour cet élève et cette période
- existing_bilan = BilanCompetence.objects.filter(student=student, period=period).first()
- if existing_bilan:
- # Supprimer le fichier physique si présent
+ for existing_bilan in BilanCompetence.objects.filter(student=student, period=period):
if existing_bilan.file and existing_bilan.file.name:
file_path = existing_bilan.file.path
if os.path.exists(file_path):
@@ -209,7 +211,6 @@ class StudentCompetencyListCreateView(APIView):
except Exception as e:
logger.error(f"Erreur lors de la sauvegarde du fichier PDF : {e}")
raise
-
return JsonResponse({"updated": updated, "errors": errors}, status=200)
@method_decorator(csrf_protect, name='dispatch')
diff --git a/Front-End/src/app/[locale]/admin/grades/studentCompetencies/page.js b/Front-End/src/app/[locale]/admin/grades/studentCompetencies/page.js
index 612faa0..433bb5c 100644
--- a/Front-End/src/app/[locale]/admin/grades/studentCompetencies/page.js
+++ b/Front-End/src/app/[locale]/admin/grades/studentCompetencies/page.js
@@ -47,12 +47,6 @@ export default function StudentCompetenciesPage() {
}
}, [studentCompetencies.data]);
- const handleScoreChange = (competencyId, score) => {
- setCompetencies((prev) =>
- prev.map((comp) => (comp.id === competencyId ? { ...comp, score } : comp))
- );
- };
-
const handleGradeChange = (competenceId, level) => {
setGrades((prev) => ({
...prev,
@@ -61,12 +55,14 @@ export default function StudentCompetenciesPage() {
};
const handleSubmit = () => {
- const data = Object.entries(grades).map(([competenceId, score]) => ({
- studentId,
- competenceId,
- grade: score,
- period: period,
- }));
+ const data = Object.entries(grades)
+ .filter(([_, score]) => [1, 2, 3].includes(score))
+ .map(([competenceId, score]) => ({
+ studentId,
+ competenceId,
+ grade: score,
+ period: period,
+ }));
editStudentCompetencies(data, csrfToken)
.then(() => {
showNotification(