fix: Application des périodes à un studentCompetency lors de la création

d'une nouvelle compétence
This commit is contained in:
N3WT DE COMPET
2025-05-30 22:07:37 +02:00
parent 4a6b7ce379
commit d65b171da8
2 changed files with 30 additions and 7 deletions

View File

@ -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,

View File

@ -147,7 +147,7 @@ export default function ValidateSubscription({
{allTemplates[currentTemplateIndex].name || 'Document sans nom'}
</h3>
<iframe
src={`${BASE_URL}/${allTemplates[currentTemplateIndex].file}`}
src={`${BASE_URL}${allTemplates[currentTemplateIndex].file}`}
title={
allTemplates[currentTemplateIndex].type === 'main'
? 'Document Principal'