fix: Correction dépendances circulaires

This commit is contained in:
N3WT DE COMPET
2025-05-12 15:16:46 +02:00
parent 52bba46cbb
commit fc9a1ed252
11 changed files with 70 additions and 60 deletions

View File

@ -2,7 +2,6 @@ from django.contrib.auth.models import AbstractUser
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.core.validators import EmailValidator from django.core.validators import EmailValidator
from Establishment.models import Establishment
class Profile(AbstractUser): class Profile(AbstractUser):
email = models.EmailField(max_length=255, unique=True, default="", validators=[EmailValidator()]) email = models.EmailField(max_length=255, unique=True, default="", validators=[EmailValidator()])
@ -25,7 +24,7 @@ class ProfileRole(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name='roles') profile = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name='roles')
role_type = models.IntegerField(choices=RoleType.choices, default=RoleType.PROFIL_UNDEFINED) role_type = models.IntegerField(choices=RoleType.choices, default=RoleType.PROFIL_UNDEFINED)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='profile_roles') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='profile_roles')
is_active = models.BooleanField(default=False) is_active = models.BooleanField(default=False)
updated_date = models.DateTimeField(auto_now=True) updated_date = models.DateTimeField(auto_now=True)

View File

3
Back-End/Common/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

6
Back-End/Common/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class CommonConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'Common'

13
Back-End/Common/models.py Normal file
View File

@ -0,0 +1,13 @@
from django.db import models
class StudentCompetency(models.Model):
student = models.ForeignKey('Subscriptions.Student', on_delete=models.CASCADE, related_name='competency_scores')
competency = models.ForeignKey('School.Competency', on_delete=models.CASCADE, related_name='student_scores')
score = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True)
comment = models.TextField(blank=True, null=True)
class Meta:
unique_together = ('student', 'competency')
def __str__(self):
return f"{self.student} - {self.competency.name} - Score: {self.score}"

3
Back-End/Common/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
Back-End/Common/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

View File

@ -1,17 +1,14 @@
from django.http.response import JsonResponse from django.http.response import JsonResponse
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
from django.core.mail import send_mail
from django.utils.html import strip_tags
from django.conf import settings from django.conf import settings
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from django.db.models import Q from django.db.models import Q
from Auth.models import Profile # Assurez-vous que le modèle Profile contient les informations nécessaires from Auth.models import Profile, ProfileRole
from .models import * from .models import *
from School.models import Teacher, ProfileRole from School.models import Teacher
from Settings.models import SMTPSettings # Assurez-vous que le chemin est correct
from GestionMessagerie.serializers import MessageSerializer from GestionMessagerie.serializers import MessageSerializer
from School.serializers import TeacherSerializer from School.serializers import TeacherSerializer

View File

@ -1,30 +1,21 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from Subscriptions.models import ( from Subscriptions.models import (
RegistrationForm, RegistrationForm,
Student, RegistrationFileGroup
Guardian,
Fee,
Discount,
RegistrationFileGroup,
RegistrationSchoolFileMaster,
RegistrationSchoolFileTemplate
) )
from Auth.models import Profile, ProfileRole from Auth.models import Profile, ProfileRole
from School.models import ( from School.models import (
FeeType, FeeType,
Speciality, Speciality,
Teacher, Teacher,
SchoolClass,
PaymentMode,
PaymentModeType, PaymentModeType,
PaymentPlan,
PaymentPlanType, PaymentPlanType,
DiscountType DiscountType,
Fee,
Discount,
) )
from django.utils import timezone from django.utils import timezone
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from django.core.files import File
from django.core.exceptions import SuspiciousFileOperation
import os import os
from django.conf import settings from django.conf import settings
from faker import Faker from faker import Faker
@ -42,7 +33,7 @@ from School.serializers import (
) )
from Auth.serializers import ProfileSerializer, ProfileRoleSerializer from Auth.serializers import ProfileSerializer, ProfileRoleSerializer
from Establishment.serializers import EstablishmentSerializer from Establishment.serializers import EstablishmentSerializer
from Subscriptions.serializers import RegistrationFormSerializer, StudentSerializer from Subscriptions.serializers import StudentSerializer
from Subscriptions.util import getCurrentSchoolYear, getNextSchoolYear # Import des fonctions nécessaires from Subscriptions.util import getCurrentSchoolYear, getNextSchoolYear # Import des fonctions nécessaires

View File

@ -1,6 +1,4 @@
from django.db import models from django.db import models
from Auth.models import ProfileRole
from Establishment.models import Establishment
from django.db.models import JSONField from django.db.models import JSONField
from django.dispatch import receiver from django.dispatch import receiver
from django.contrib.postgres.fields import ArrayField from django.contrib.postgres.fields import ArrayField
@ -23,7 +21,7 @@ class Speciality(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
updated_date = models.DateTimeField(auto_now=True) updated_date = models.DateTimeField(auto_now=True)
color_code = models.CharField(max_length=7, default='#FFFFFF') color_code = models.CharField(max_length=7, default='#FFFFFF')
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='specialities') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='specialities')
def __str__(self): def __str__(self):
return self.name return self.name
@ -32,7 +30,7 @@ class Teacher(models.Model):
last_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100)
first_name = models.CharField(max_length=100) first_name = models.CharField(max_length=100)
specialities = models.ManyToManyField(Speciality, blank=True) specialities = models.ManyToManyField(Speciality, blank=True)
profile_role = models.OneToOneField(ProfileRole, on_delete=models.CASCADE, related_name='teacher_profile', null=True, blank=True) profile_role = models.OneToOneField('Auth.ProfileRole', on_delete=models.CASCADE, related_name='teacher_profile', null=True, blank=True)
updated_date = models.DateTimeField(auto_now=True) updated_date = models.DateTimeField(auto_now=True)
def __str__(self): def __str__(self):
@ -56,7 +54,7 @@ class SchoolClass(models.Model):
type = models.IntegerField(choices=PLANNING_TYPE_CHOICES, default=1) type = models.IntegerField(choices=PLANNING_TYPE_CHOICES, default=1)
time_range = models.JSONField(default=list) time_range = models.JSONField(default=list)
opening_days = ArrayField(models.IntegerField(), default=list) opening_days = ArrayField(models.IntegerField(), default=list)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='school_classes') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='school_classes')
def __str__(self): def __str__(self):
return self.atmosphere_name return self.atmosphere_name
@ -96,7 +94,7 @@ class Discount(models.Model):
discount_type = models.IntegerField(choices=DiscountType.choices, default=DiscountType.CURRENCY) discount_type = models.IntegerField(choices=DiscountType.choices, default=DiscountType.CURRENCY)
type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE) type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='discounts') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='discounts')
def __str__(self): def __str__(self):
return self.name return self.name
@ -108,7 +106,7 @@ class Fee(models.Model):
is_active = models.BooleanField(default=True) is_active = models.BooleanField(default=True)
updated_at = models.DateTimeField(auto_now=True) updated_at = models.DateTimeField(auto_now=True)
type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE) type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='fees') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='fees')
def __str__(self): def __str__(self):
return self.name return self.name
@ -118,7 +116,7 @@ class PaymentPlan(models.Model):
due_dates = ArrayField(models.DateField(), blank=True) due_dates = ArrayField(models.DateField(), blank=True)
type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE) type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE)
is_active = models.BooleanField(default=False) is_active = models.BooleanField(default=False)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='payment_plans') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='payment_plans')
def __str__(self): def __str__(self):
return f"{self.get_frequency_display()} - {self.get_type_display()}" return f"{self.get_frequency_display()} - {self.get_type_display()}"
@ -127,7 +125,7 @@ class PaymentMode(models.Model):
mode = models.IntegerField(choices=PaymentModeType.choices, default=PaymentModeType.SEPA) mode = models.IntegerField(choices=PaymentModeType.choices, default=PaymentModeType.SEPA)
type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE) type = models.IntegerField(choices=FeeType.choices, default=FeeType.REGISTRATION_FEE)
is_active = models.BooleanField(default=False) is_active = models.BooleanField(default=False)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='payment_modes') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='payment_modes')
def __str__(self): def __str__(self):
return f"{self.get_mode_display()} - {self.get_type_display()}" return f"{self.get_mode_display()} - {self.get_type_display()}"
@ -155,7 +153,7 @@ class Competency(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='competencies') category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='competencies')
establishments = models.ManyToManyField( establishments = models.ManyToManyField(
Establishment, 'Establishment.Establishment',
through='EstablishmentCompetency', through='EstablishmentCompetency',
related_name='competencies', related_name='competencies',
blank=True blank=True
@ -169,7 +167,7 @@ class EstablishmentCompetency(models.Model):
Relation entre un établissement et une compétence. Relation entre un établissement et une compétence.
Permet de définir quelles compétences sont sélectionnées par un établissement. Permet de définir quelles compétences sont sélectionnées par un établissement.
""" """
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE) establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE)
competency = models.ForeignKey(Competency, on_delete=models.CASCADE) competency = models.ForeignKey(Competency, on_delete=models.CASCADE)
is_selected = models.BooleanField(default=False) is_selected = models.BooleanField(default=False)
@ -180,18 +178,18 @@ class EstablishmentCompetency(models.Model):
return f"{self.establishment.name} - {self.competency.name}" return f"{self.establishment.name} - {self.competency.name}"
class StudentCompetency(models.Model): # class StudentCompetency(models.Model):
""" # """
Relation entre un élève et une compétence. # Relation entre un élève et une compétence.
Permet d'attribuer une note à un élève pour une compétence. # Permet d'attribuer une note à un élève pour une compétence.
""" # """
student = models.ForeignKey('Subscriptions.Student', on_delete=models.CASCADE, related_name='competency_scores') # student = models.ForeignKey('Subscriptions.Student', on_delete=models.CASCADE, related_name='competency_scores')
competency = models.ForeignKey(Competency, on_delete=models.CASCADE, related_name='student_scores') # competency = models.ForeignKey(Competency, on_delete=models.CASCADE, related_name='student_scores')
score = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True) # Note attribuée # score = models.DecimalField(max_digits=5, decimal_places=2, null=True, blank=True) # Note attribuée
comment = models.TextField(blank=True, null=True) # Commentaire facultatif # comment = models.TextField(blank=True, null=True) # Commentaire facultatif
class Meta: # class Meta:
unique_together = ('student', 'competency') # unique_together = ('student', 'competency')
def __str__(self): # def __str__(self):
return f"{self.student} - {self.competency.name} - Score: {self.score}" # return f"{self.student} - {self.competency.name} - Score: {self.score}"

View File

@ -3,11 +3,8 @@ from django.utils.timezone import now
from django.conf import settings from django.conf import settings
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from School.models import SchoolClass, Fee, Discount, PaymentModeType, PaymentPlanType
from Auth.models import ProfileRole
from Establishment.models import Establishment
from datetime import datetime from datetime import datetime
from School.models import PaymentModeType, PaymentPlanType
import os import os
@ -31,7 +28,7 @@ class Guardian(models.Model):
address = models.CharField(max_length=200, default="", blank=True) address = models.CharField(max_length=200, default="", blank=True)
phone = models.CharField(max_length=200, default="", blank=True) phone = models.CharField(max_length=200, default="", blank=True)
profession = models.CharField(max_length=200, default="", blank=True) profession = models.CharField(max_length=200, default="", blank=True)
profile_role = models.OneToOneField(ProfileRole, on_delete=models.CASCADE, related_name='guardian_profile', null=True, blank=True) profile_role = models.OneToOneField('Auth.ProfileRole', on_delete=models.CASCADE, related_name='guardian_profile', null=True, blank=True)
@property @property
def email(self): def email(self):
@ -100,19 +97,19 @@ class Student(models.Model):
profiles = models.ManyToManyField('Auth.Profile', blank=True) profiles = models.ManyToManyField('Auth.Profile', blank=True)
# Many-to-Many Relationship # Many-to-Many Relationship
guardians = models.ManyToManyField(Guardian, blank=True) guardians = models.ManyToManyField('Subscriptions.Guardian', blank=True)
# Many-to-Many Relationship # Many-to-Many Relationship
siblings = models.ManyToManyField(Sibling, blank=True) siblings = models.ManyToManyField('Subscriptions.Sibling', blank=True)
# Many-to-Many Relationship # Many-to-Many Relationship
registration_files = models.ManyToManyField('RegistrationSchoolFileTemplate', blank=True, related_name='students') registration_files = models.ManyToManyField('Subscriptions.RegistrationSchoolFileTemplate', blank=True, related_name='students')
# Many-to-Many Relationship # Many-to-Many Relationship
spoken_languages = models.ManyToManyField(Language, blank=True) spoken_languages = models.ManyToManyField('Subscriptions.Language', blank=True)
# One-to-Many Relationship # One-to-Many Relationship
associated_class = models.ForeignKey(SchoolClass, on_delete=models.SET_NULL, null=True, blank=True, related_name='students') associated_class = models.ForeignKey('School.SchoolClass', on_delete=models.SET_NULL, null=True, blank=True, related_name='students')
def __str__(self): def __str__(self):
return self.last_name + "_" + self.first_name return self.last_name + "_" + self.first_name
@ -190,7 +187,7 @@ class Student(models.Model):
class RegistrationFileGroup(models.Model): class RegistrationFileGroup(models.Model):
name = models.CharField(max_length=255, default="") name = models.CharField(max_length=255, default="")
description = models.TextField(blank=True, null=True) description = models.TextField(blank=True, null=True)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='file_group', null=True, blank=True) establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='file_group', null=True, blank=True)
def __str__(self): def __str__(self):
return self.name return self.name
@ -239,17 +236,17 @@ class RegistrationForm(models.Model):
associated_rf = models.CharField(max_length=200, default="", blank=True) associated_rf = models.CharField(max_length=200, default="", blank=True)
# Many-to-Many Relationship # Many-to-Many Relationship
fees = models.ManyToManyField(Fee, blank=True, related_name='register_forms') fees = models.ManyToManyField('School.Fee', blank=True, related_name='register_forms')
# Many-to-Many Relationship # Many-to-Many Relationship
discounts = models.ManyToManyField(Discount, blank=True, related_name='register_forms') discounts = models.ManyToManyField('School.Discount', blank=True, related_name='register_forms')
fileGroup = models.ForeignKey(RegistrationFileGroup, fileGroup = models.ForeignKey(RegistrationFileGroup,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name='register_forms', related_name='register_forms',
null=True, null=True,
blank=True) blank=True)
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='register_forms') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='register_forms')
registration_payment = models.IntegerField(choices=PaymentModeType.choices, null=True, blank=True) registration_payment = models.IntegerField(choices=PaymentModeType.choices, null=True, blank=True)
tuition_payment = models.IntegerField(choices=PaymentModeType.choices, null=True, blank=True) tuition_payment = models.IntegerField(choices=PaymentModeType.choices, null=True, blank=True)
registration_payment_plan = models.IntegerField(choices=PaymentPlanType.choices, null=True, blank=True) registration_payment_plan = models.IntegerField(choices=PaymentPlanType.choices, null=True, blank=True)
@ -386,7 +383,7 @@ class AbsenceManagement(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name='absences' related_name='absences'
) )
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='absences') establishment = models.ForeignKey('Establishment.Establishment', on_delete=models.CASCADE, related_name='absences')
def __str__(self): def __str__(self):
return f"{self.student} - {self.day} - {self.get_moment_display()} - {self.get_reason_display()}" return f"{self.student} - {self.day} - {self.get_moment_display()} - {self.get_reason_display()}"