mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
chore: Ajout d'un mode test au lancement du serveur pour ajouter des
datas de test
This commit is contained in:
160
Back-End/School/management/commands/init_school_configuration.py
Normal file
160
Back-End/School/management/commands/init_school_configuration.py
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from Auth.models import Profile
|
||||||
|
from School.models import Speciality, Teacher, SchoolClass
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Initialize or update Fees and Discounts'
|
||||||
|
|
||||||
|
def handle(self, *args, **kwargs):
|
||||||
|
self.create_or_update_specialities()
|
||||||
|
self.create_or_update_teachers()
|
||||||
|
self.create_or_update_schoolClasses()
|
||||||
|
|
||||||
|
def create_or_update_specialities(self):
|
||||||
|
specialities_data = [
|
||||||
|
{
|
||||||
|
"name": "GROUPE",
|
||||||
|
"color_code": "#FF0000"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "MATHS",
|
||||||
|
"color_code": "#0a98f0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ANGLAIS",
|
||||||
|
"color_code": "#f708d7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "FRANCAIS",
|
||||||
|
"color_code": "#04f108"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "HISTOIRE",
|
||||||
|
"color_code": "#ffb005"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SPORT",
|
||||||
|
"color_code": "#bbb9b9"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for speciality_data in specialities_data:
|
||||||
|
Speciality.objects.update_or_create(
|
||||||
|
name=speciality_data["name"],
|
||||||
|
defaults=speciality_data
|
||||||
|
)
|
||||||
|
self.stdout.write(self.style.SUCCESS('Specialities initialized or updated successfully'))
|
||||||
|
|
||||||
|
def create_or_update_teachers(self):
|
||||||
|
teachers_data = [
|
||||||
|
{
|
||||||
|
"last_name": "DUMBLEDORE",
|
||||||
|
"first_name": "Albus",
|
||||||
|
"email": "albus.dumbledore@gmail.com",
|
||||||
|
"specialities": ["GROUPE"],
|
||||||
|
"droit": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"last_name": "ROGUE",
|
||||||
|
"first_name": "Severus",
|
||||||
|
"email": "severus.rogue@gmail.com",
|
||||||
|
"specialities": ["ANGLAIS"],
|
||||||
|
"droit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"last_name": "MC GONAGALL",
|
||||||
|
"first_name": "Minerva",
|
||||||
|
"email": "minerva.mcgonagall@gmail.com",
|
||||||
|
"specialities": ["MATHS", "HISTOIRE"],
|
||||||
|
"droit": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"last_name": "CHOURAVE",
|
||||||
|
"first_name": "Pomona",
|
||||||
|
"email": "pomona.chourave@gmail.com",
|
||||||
|
"specialities": ["MATHS", "FRANCAIS", "SPORT"],
|
||||||
|
"droit": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for teacher_data in teachers_data:
|
||||||
|
specialities = teacher_data.pop("specialities")
|
||||||
|
email = teacher_data["email"]
|
||||||
|
droit = teacher_data.pop("droit")
|
||||||
|
|
||||||
|
# Create or update the user profile
|
||||||
|
user, created = Profile.objects.update_or_create(
|
||||||
|
email=email,
|
||||||
|
defaults={
|
||||||
|
"username": email,
|
||||||
|
"email": email,
|
||||||
|
"is_active": True,
|
||||||
|
"password": "Provisoire01!",
|
||||||
|
"droit": droit
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if created:
|
||||||
|
user.set_password("Provisoire01!")
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
# Create or update the teacher
|
||||||
|
teacher, created = Teacher.objects.update_or_create(
|
||||||
|
email=email,
|
||||||
|
defaults={**teacher_data, "associated_profile_id": user.id}
|
||||||
|
)
|
||||||
|
teacher.specialities.set(Speciality.objects.filter(name__in=specialities))
|
||||||
|
teacher.save()
|
||||||
|
|
||||||
|
self.stdout.write(self.style.SUCCESS('Teachers initialized or updated successfully'))
|
||||||
|
|
||||||
|
def create_or_update_schoolClasses(self):
|
||||||
|
school_classes_data = [
|
||||||
|
{
|
||||||
|
"atmosphere_name": "Classe A",
|
||||||
|
"age_range": "3-6",
|
||||||
|
"number_of_students": 14,
|
||||||
|
"teaching_language": "",
|
||||||
|
"school_year": "2024-2025",
|
||||||
|
"levels": [2, 3, 4],
|
||||||
|
"type": 1,
|
||||||
|
"time_range": ["08:30", "17:30"],
|
||||||
|
"opening_days": [1, 2, 4, 5],
|
||||||
|
"teachers": [2] # ID of Severus Rogue
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"atmosphere_name": "Classe B",
|
||||||
|
"age_range": "2-3",
|
||||||
|
"number_of_students": 5,
|
||||||
|
"teaching_language": "",
|
||||||
|
"school_year": "2024-2025",
|
||||||
|
"levels": [1],
|
||||||
|
"type": 1,
|
||||||
|
"time_range": ["08:30", "17:30"],
|
||||||
|
"opening_days": [1, 2, 4, 5],
|
||||||
|
"teachers": [3] # ID of Minerva McGonagall
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"atmosphere_name": "Classe C",
|
||||||
|
"age_range": "6-12",
|
||||||
|
"number_of_students": 21,
|
||||||
|
"teaching_language": "",
|
||||||
|
"school_year": "2024-2025",
|
||||||
|
"levels": [5, 6, 7, 8, 9],
|
||||||
|
"type": 1,
|
||||||
|
"time_range": ["08:30", "17:30"],
|
||||||
|
"opening_days": [1, 2, 4, 5],
|
||||||
|
"teachers": [4] # ID of Pomona Chourave
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for class_data in school_classes_data:
|
||||||
|
teachers_ids = class_data.pop("teachers")
|
||||||
|
school_class, created = SchoolClass.objects.update_or_create(
|
||||||
|
atmosphere_name=class_data["atmosphere_name"],
|
||||||
|
school_year=class_data["school_year"],
|
||||||
|
defaults=class_data
|
||||||
|
)
|
||||||
|
school_class.teachers.set(teachers_ids)
|
||||||
|
school_class.save()
|
||||||
|
|
||||||
|
self.stdout.write(self.style.SUCCESS('SchoolClasses initialized or updated successfully'))
|
||||||
@ -1,4 +1,5 @@
|
|||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
from Auth.models import Profile
|
||||||
from School.models import Fee, Discount, FeeType, DiscountType
|
from School.models import Fee, Discount, FeeType, DiscountType
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -83,3 +84,4 @@ class Command(BaseCommand):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.stdout.write(self.style.SUCCESS('Discounts initialized or updated successfully'))
|
self.stdout.write(self.style.SUCCESS('Discounts initialized or updated successfully'))
|
||||||
|
|
||||||
@ -10,6 +10,8 @@ def run_command(command):
|
|||||||
print(f"stderr: {stderr.decode()}")
|
print(f"stderr: {stderr.decode()}")
|
||||||
return process.returncode
|
return process.returncode
|
||||||
|
|
||||||
|
test_mode = os.getenv('TEST_MODE', 'False') == 'True'
|
||||||
|
|
||||||
commands = [
|
commands = [
|
||||||
["python", "manage.py", "collectstatic", "--noinput"],
|
["python", "manage.py", "collectstatic", "--noinput"],
|
||||||
["python", "manage.py", "flush", "--noinput"],
|
["python", "manage.py", "flush", "--noinput"],
|
||||||
@ -20,14 +22,23 @@ commands = [
|
|||||||
["python", "manage.py", "makemigrations", "School", "--noinput"],
|
["python", "manage.py", "makemigrations", "School", "--noinput"],
|
||||||
["python", "manage.py", "migrate", "--noinput"],
|
["python", "manage.py", "migrate", "--noinput"],
|
||||||
["python", "manage.py", "init_payment_plans"],
|
["python", "manage.py", "init_payment_plans"],
|
||||||
["python", "manage.py", "init_payment_modes"],
|
["python", "manage.py", "init_payment_modes"]
|
||||||
["python", "manage.py", "init_data"]
|
]
|
||||||
|
|
||||||
|
test_commands = [
|
||||||
|
["python", "manage.py", "init_school_configuration"],
|
||||||
|
["python", "manage.py", "init_school_fees"]
|
||||||
]
|
]
|
||||||
|
|
||||||
for command in commands:
|
for command in commands:
|
||||||
if run_command(command) != 0:
|
if run_command(command) != 0:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
if test_mode:
|
||||||
|
for test_command in test_commands:
|
||||||
|
if run_command(test_command) != 0:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
# Lancer les processus en parallèle
|
# Lancer les processus en parallèle
|
||||||
processes = [
|
processes = [
|
||||||
subprocess.Popen(["python", "manage.py", "runserver", "0.0.0.0:8080"]),
|
subprocess.Popen(["python", "manage.py", "runserver", "0.0.0.0:8080"]),
|
||||||
|
|||||||
@ -47,6 +47,7 @@ services:
|
|||||||
- ./Back-End:/Back-End
|
- ./Back-End:/Back-End
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Paris
|
- TZ=Europe/Paris
|
||||||
|
- TEST_MODE=True
|
||||||
links:
|
links:
|
||||||
- "database:database"
|
- "database:database"
|
||||||
- "redis:redis"
|
- "redis:redis"
|
||||||
|
|||||||
Reference in New Issue
Block a user