mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
fix: Génération uniquement des compétences évaluées dans le PDF
This commit is contained in:
@ -44,7 +44,7 @@
|
||||
<th colspan="4" style="text-align:center">{{ domaine.nom }}</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="competence-header" style="min-width: 120px;">Compétence</th>
|
||||
<th class="competence-header" style="min-width: 120px;">Compétences</th>
|
||||
<th class="competence-header" style="width: 28px; text-align:center;">1</th>
|
||||
<th class="competence-header" style="width: 28px; text-align:center;">2</th>
|
||||
<th class="competence-header" style="width: 28px; text-align:center;">3</th>
|
||||
|
||||
@ -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:
|
||||
@ -184,13 +190,9 @@ 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')
|
||||
|
||||
@ -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(
|
||||
|
||||
Reference in New Issue
Block a user