From d65b171da8a310acca15936a39e44239763c88b9 Mon Sep 17 00:00:00 2001 From: N3WT DE COMPET Date: Fri, 30 May 2025 22:07:37 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20Application=20des=20p=C3=A9riodes=20?= =?UTF-8?q?=C3=A0=20un=20studentCompetency=20lors=20de=20la=20cr=C3=A9atio?= =?UTF-8?q?n=20d'une=20nouvelle=20comp=C3=A9tence?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Back-End/School/views.py | 35 +++++++++++++++---- .../Inscription/ValidateSubscription.js | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Back-End/School/views.py b/Back-End/School/views.py index 3cc91d3..6725bcc 100644 --- a/Back-End/School/views.py +++ b/Back-End/School/views.py @@ -33,6 +33,10 @@ from N3wtSchool.bdd import delete_object, getAllObjects, getObject from django.db.models import Q from collections import defaultdict from Subscriptions.models import Student, StudentCompetency +from Subscriptions.util import getCurrentSchoolYear +import logging + +logger = logging.getLogger(__name__) @method_decorator(csrf_protect, name='dispatch') @method_decorator(ensure_csrf_cookie, name='dispatch') @@ -478,6 +482,7 @@ class CompetencyDetailView(APIView): @method_decorator(ensure_csrf_cookie, name='dispatch') class EstablishmentCompetencyListCreateView(APIView): def get(self, request): + logger.info('coucou') establishment_id = request.GET.get('establishment_id') cycle = request.GET.get('cycle') if not establishment_id or not cycle: @@ -581,7 +586,6 @@ class EstablishmentCompetencyListCreateView(APIView): try: category = Category.objects.get(id=category_id) - # Vérifier si une compétence custom du même nom existe déjà pour cet établissement et cette catégorie ec_exists = EstablishmentCompetency.objects.filter( establishment_id=establishment_id, competency__isnull=True, @@ -598,13 +602,32 @@ class EstablishmentCompetencyListCreateView(APIView): custom_category=category, is_required=False ) - # Associer à tous les élèves de l'établissement + + # Récupérer l'établissement et sa fréquence d'évaluation + establishment = ec.establishment + evaluation_frequency = establishment.evaluation_frequency # 1=Trimestre, 2=Semestre, 3=Année + + # Déterminer l'année scolaire courante + school_year = getCurrentSchoolYear() + + # Générer les périodes selon la fréquence + periods = [] + if evaluation_frequency == 1: # Trimestre + periods = [f"T{i+1}_{school_year}" for i in range(3)] + elif evaluation_frequency == 2: # Semestre + periods = [f"S{i+1}_{school_year}" for i in range(2)] + elif evaluation_frequency == 3: # Année + periods = [f"A_{school_year}"] + + # Associer à tous les élèves de l'établissement pour chaque période students = Student.objects.filter(associated_class__establishment_id=establishment_id) for student in students: - StudentCompetency.objects.get_or_create( - student=student, - establishment_competency=ec - ) + for period in periods: + StudentCompetency.objects.get_or_create( + student=student, + establishment_competency=ec, + period=period + ) created.append({ "competence_id": ec.id, diff --git a/Front-End/src/components/Inscription/ValidateSubscription.js b/Front-End/src/components/Inscription/ValidateSubscription.js index 691a0d8..dcd7ae1 100644 --- a/Front-End/src/components/Inscription/ValidateSubscription.js +++ b/Front-End/src/components/Inscription/ValidateSubscription.js @@ -147,7 +147,7 @@ export default function ValidateSubscription({ {allTemplates[currentTemplateIndex].name || 'Document sans nom'}