mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Utilisation de l'établissement en variable de session / gestion de
la page des inscriptions en fonction de l'établissement / mise à jour du mock_data à l'init
This commit is contained in:
@ -31,12 +31,17 @@ from django.core.exceptions import SuspiciousFileOperation
|
||||
import os
|
||||
from django.conf import settings
|
||||
from faker import Faker
|
||||
import random
|
||||
import json
|
||||
|
||||
# Définir le chemin vers le dossier mock_datas
|
||||
MOCK_DATAS_PATH = os.path.join(settings.BASE_DIR, 'School', 'management', 'mock_datas')
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Initialise toutes les données mock'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
self.create_or_update_establishment()
|
||||
self.create_or_update_establishments()
|
||||
self.create_or_update_fees()
|
||||
self.create_or_update_discounts()
|
||||
self.create_or_update_payment_modes()
|
||||
@ -47,71 +52,32 @@ class Command(BaseCommand):
|
||||
self.create_or_update_registration_file_group()
|
||||
self.create_register_form()
|
||||
|
||||
def create_or_update_establishment(self):
|
||||
establishment_data = {
|
||||
"name": "N3WT",
|
||||
"address": "Société n3wt-innov 69 Chez LANA",
|
||||
"total_capacity": 69,
|
||||
"establishment_type": [StructureType.MATERNELLE, StructureType.PRIMAIRE],
|
||||
"licence_code": ""
|
||||
}
|
||||
def load_data(self, filename):
|
||||
with open(os.path.join(MOCK_DATAS_PATH, filename), 'r') as file:
|
||||
return json.load(file)
|
||||
|
||||
establishment, created = Establishment.objects.update_or_create(
|
||||
name=establishment_data["name"],
|
||||
defaults=establishment_data
|
||||
)
|
||||
def create_or_update_establishments(self):
|
||||
establishments_data = self.load_data('establishments.json')
|
||||
|
||||
if created:
|
||||
self.stdout.write(self.style.SUCCESS('Establishment created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS('Establishment updated successfully'))
|
||||
self.establishments = []
|
||||
for establishment_data in establishments_data:
|
||||
establishment, created = Establishment.objects.update_or_create(
|
||||
name=establishment_data["name"],
|
||||
defaults=establishment_data
|
||||
)
|
||||
self.establishments.append(establishment)
|
||||
if created:
|
||||
self.stdout.write(self.style.SUCCESS(f'Establishment {establishment.name} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS(f'Establishment {establishment.name} updated successfully'))
|
||||
|
||||
def create_or_update_fees(self):
|
||||
establishment = Establishment.objects.get(name="N3WT")
|
||||
fees_data = [
|
||||
{
|
||||
"name": "Frais d'inscription",
|
||||
"base_amount": "150.00",
|
||||
"description": "Montant de base",
|
||||
"is_active": True,
|
||||
"type": FeeType.REGISTRATION_FEE,
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"name": "Matériel",
|
||||
"base_amount": "85.00",
|
||||
"description": "Livres / jouets",
|
||||
"is_active": True,
|
||||
"type": FeeType.REGISTRATION_FEE,
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"name": "Sorties périscolaires",
|
||||
"base_amount": "120.00",
|
||||
"description": "Sorties",
|
||||
"is_active": True,
|
||||
"type": FeeType.REGISTRATION_FEE,
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"name": "Les colibris",
|
||||
"base_amount": "4500.00",
|
||||
"description": "TPS / PS / MS / GS",
|
||||
"is_active": True,
|
||||
"type": FeeType.TUITION_FEE,
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"name": "Les butterflies",
|
||||
"base_amount": "5000.00",
|
||||
"description": "CP / CE1 / CE2 / CM1 / CM2",
|
||||
"is_active": True,
|
||||
"type": FeeType.TUITION_FEE,
|
||||
"establishment": establishment
|
||||
}
|
||||
]
|
||||
fees_data = self.load_data('fees.json')
|
||||
|
||||
for fee_data in fees_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
fee_data["name"] = f"{fee_data['name']} - {establishment.name}"
|
||||
fee_data["establishment"] = establishment
|
||||
Fee.objects.update_or_create(
|
||||
name=fee_data["name"],
|
||||
type=fee_data["type"],
|
||||
@ -121,27 +87,12 @@ class Command(BaseCommand):
|
||||
self.stdout.write(self.style.SUCCESS('Fees initialized or updated successfully'))
|
||||
|
||||
def create_or_update_discounts(self):
|
||||
establishment = Establishment.objects.get(name="N3WT")
|
||||
discounts_data = [
|
||||
{
|
||||
"name": "Parrainage",
|
||||
"amount": "10.00",
|
||||
"description": "Réduction pour parrainage",
|
||||
"discount_type": DiscountType.PERCENT,
|
||||
"type": FeeType.TUITION_FEE,
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"name": "Réinscription",
|
||||
"amount": "100.00",
|
||||
"description": "Réduction pour Réinscription",
|
||||
"discount_type": DiscountType.PERCENT,
|
||||
"type": FeeType.REGISTRATION_FEE,
|
||||
"establishment": establishment
|
||||
}
|
||||
]
|
||||
discounts_data = self.load_data('discounts.json')
|
||||
|
||||
for discount_data in discounts_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
discount_data["name"] = f"{discount_data['name']} - {establishment.name}"
|
||||
discount_data["establishment"] = establishment
|
||||
Discount.objects.update_or_create(
|
||||
name=discount_data["name"],
|
||||
type=discount_data["type"],
|
||||
@ -152,104 +103,44 @@ class Command(BaseCommand):
|
||||
self.stdout.write(self.style.SUCCESS('Discounts initialized or updated successfully'))
|
||||
|
||||
def create_or_update_payment_modes(self):
|
||||
establishment = Establishment.objects.get(name="N3WT")
|
||||
for fee_type in FeeType.choices:
|
||||
fee_type_value = fee_type[0]
|
||||
payment_modes_data = self.load_data('payment_modes.json')
|
||||
|
||||
for mode in PaymentModeType.choices:
|
||||
mode_value = mode[0]
|
||||
|
||||
PaymentMode.objects.update_or_create(
|
||||
mode=mode_value,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'is_active': False,
|
||||
'establishment': establishment
|
||||
}
|
||||
)
|
||||
for payment_mode_data in payment_modes_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
payment_mode_data["establishment"] = establishment
|
||||
PaymentMode.objects.update_or_create(
|
||||
mode=payment_mode_data["mode"],
|
||||
type=payment_mode_data["type"],
|
||||
defaults=payment_mode_data
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Payment Modes initialized or updated successfully'))
|
||||
|
||||
def create_or_update_payment_plans(self):
|
||||
payment_plans_data = self.load_data('payment_plans.json')
|
||||
current_date = timezone.now().date()
|
||||
establishment = Establishment.objects.get(name="N3WT")
|
||||
|
||||
for fee_type in FeeType.choices:
|
||||
fee_type_value = fee_type[0]
|
||||
for payment_plan_data in payment_plans_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
payment_plan_data["establishment"] = establishment
|
||||
payment_plan_data["due_dates"] = [current_date + relativedelta(months=1)]
|
||||
if payment_plan_data["frequency"] == PaymentPlanType.THREE_TIMES:
|
||||
payment_plan_data["due_dates"] = [current_date + relativedelta(months=1+4*i) for i in range(3)]
|
||||
elif payment_plan_data["frequency"] == PaymentPlanType.TEN_TIMES:
|
||||
payment_plan_data["due_dates"] = [current_date + relativedelta(months=1+i) for i in range(10)]
|
||||
elif payment_plan_data["frequency"] == PaymentPlanType.TWELVE_TIMES:
|
||||
payment_plan_data["due_dates"] = [current_date + relativedelta(months=1+i) for i in range(12)]
|
||||
|
||||
# 1 fois - échéance à 1 mois à partir de la date actuelle
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.ONE_TIME,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1)],
|
||||
'is_active': True,
|
||||
'establishment': establishment
|
||||
}
|
||||
)
|
||||
|
||||
# 3 fois - échéances espacées de 4 mois
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.THREE_TIMES,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1+4*i) for i in range(3)],
|
||||
'is_active': False,
|
||||
'establishment': establishment
|
||||
}
|
||||
)
|
||||
|
||||
# 10 fois - échéances espacées d'un mois
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.TEN_TIMES,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1+i) for i in range(10)],
|
||||
'is_active': False,
|
||||
'establishment': establishment
|
||||
}
|
||||
)
|
||||
|
||||
# 12 fois - échéances espacées d'un mois
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=PaymentPlanType.TWELVE_TIMES,
|
||||
type=fee_type_value,
|
||||
defaults={
|
||||
'due_dates': [current_date + relativedelta(months=1+i) for i in range(12)],
|
||||
'is_active': False,
|
||||
'establishment': establishment
|
||||
}
|
||||
frequency=payment_plan_data["frequency"],
|
||||
type=payment_plan_data["type"],
|
||||
defaults=payment_plan_data
|
||||
)
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Payment Plans initialized or updated successfully'))
|
||||
|
||||
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"
|
||||
}
|
||||
]
|
||||
specialities_data = self.load_data('specialities.json')
|
||||
|
||||
for speciality_data in specialities_data:
|
||||
Speciality.objects.update_or_create(
|
||||
@ -259,42 +150,15 @@ class Command(BaseCommand):
|
||||
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
|
||||
}
|
||||
]
|
||||
teachers_data = self.load_data('teachers.json')
|
||||
|
||||
for teacher_data in teachers_data:
|
||||
specialities = teacher_data.pop("specialities")
|
||||
email = teacher_data["email"]
|
||||
droit = teacher_data.pop("droit")
|
||||
|
||||
establishment = random.choice(self.establishments)
|
||||
|
||||
# Create or update the user profile
|
||||
user, created = Profile.objects.update_or_create(
|
||||
email=email,
|
||||
@ -303,7 +167,8 @@ class Command(BaseCommand):
|
||||
"email": email,
|
||||
"is_active": True,
|
||||
"password": "Provisoire01!",
|
||||
"droit": droit
|
||||
"droit": droit,
|
||||
"establishment": establishment
|
||||
}
|
||||
)
|
||||
if created:
|
||||
@ -321,51 +186,13 @@ class Command(BaseCommand):
|
||||
self.stdout.write(self.style.SUCCESS('Teachers initialized or updated successfully'))
|
||||
|
||||
def create_or_update_school_classes(self):
|
||||
establishment = Establishment.objects.get(name="N3WT")
|
||||
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
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"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
|
||||
"establishment": establishment
|
||||
},
|
||||
{
|
||||
"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
|
||||
"establishment": establishment
|
||||
}
|
||||
]
|
||||
school_classes_data = self.load_data('school_classes.json')
|
||||
|
||||
for class_data in school_classes_data:
|
||||
for index, class_data in enumerate(school_classes_data, start=1):
|
||||
teachers_ids = class_data.pop("teachers")
|
||||
establishment = random.choice(self.establishments)
|
||||
class_data["atmosphere_name"] = f"Classe {index} - {establishment.name}"
|
||||
class_data["establishment"] = establishment
|
||||
school_class, created = SchoolClass.objects.update_or_create(
|
||||
atmosphere_name=class_data["atmosphere_name"],
|
||||
school_year=class_data["school_year"],
|
||||
@ -377,33 +204,29 @@ class Command(BaseCommand):
|
||||
self.stdout.write(self.style.SUCCESS('SchoolClasses initialized or updated successfully'))
|
||||
|
||||
def create_or_update_registration_file_group(self):
|
||||
group_data_1 = {
|
||||
"name": "LMDE",
|
||||
"description": "Fichiers d'inscription de l'école LMDE"
|
||||
}
|
||||
for establishment in self.establishments:
|
||||
group_data = {
|
||||
"name": f"Fichiers d'inscription - {establishment.name}",
|
||||
"description": f"Fichiers d'inscription de l'école {establishment.name}"
|
||||
}
|
||||
|
||||
self.registration_file_group_1, created = RegistrationFileGroup.objects.get_or_create(name=group_data_1["name"], defaults=group_data_1)
|
||||
self.stdout.write(self.style.SUCCESS('RegistrationFileGroup 1 initialized or updated successfully'))
|
||||
|
||||
group_data_2 = {
|
||||
"name": "LMDE 2",
|
||||
"description": "Fichiers d'inscription de l'école LMDE 2"
|
||||
}
|
||||
|
||||
self.registration_file_group_2, created = RegistrationFileGroup.objects.get_or_create(name=group_data_2["name"], defaults=group_data_2)
|
||||
self.stdout.write(self.style.SUCCESS('RegistrationFileGroup 2 initialized or updated successfully'))
|
||||
RegistrationFileGroup.objects.update_or_create(name=group_data["name"], defaults=group_data)
|
||||
self.stdout.write(self.style.SUCCESS(f'RegistrationFileGroup for {establishment.name} initialized or updated successfully'))
|
||||
|
||||
def create_register_form(self):
|
||||
fake = Faker('fr_FR') # Utiliser le locale français pour Faker
|
||||
|
||||
for _ in range(50):
|
||||
establishment = random.choice(self.establishments)
|
||||
|
||||
# Générer des données fictives pour le profil
|
||||
profile_data = {
|
||||
"email": fake.email(),
|
||||
"droit": 2,
|
||||
"username": fake.user_name(),
|
||||
"is_active": True,
|
||||
"password": "Provisoire01!"
|
||||
"password": "Provisoire01!",
|
||||
"establishment": establishment
|
||||
}
|
||||
|
||||
user, created = Profile.objects.update_or_create(
|
||||
@ -412,7 +235,8 @@ class Command(BaseCommand):
|
||||
"username": profile_data["username"],
|
||||
"email": profile_data["email"],
|
||||
"is_active": profile_data["is_active"],
|
||||
"droit": profile_data["droit"]
|
||||
"droit": profile_data["droit"],
|
||||
"establishment": profile_data["establishment"]
|
||||
}
|
||||
)
|
||||
if created:
|
||||
@ -427,7 +251,7 @@ class Command(BaseCommand):
|
||||
|
||||
# Générer des données fictives pour l'étudiant
|
||||
student_data = {
|
||||
"last_name": fake.last_name(),
|
||||
"last_name": f"{fake.last_name()} - {establishment.name}",
|
||||
"first_name": fake.first_name(),
|
||||
"address": fake.address(),
|
||||
"birth_date": fake.date_of_birth(),
|
||||
@ -457,8 +281,8 @@ class Command(BaseCommand):
|
||||
# Créer les données du formulaire d'inscription
|
||||
register_form_data = {
|
||||
"student": student,
|
||||
"fileGroup": self.registration_file_group_1,
|
||||
"establishment": Establishment.objects.get(id=1),
|
||||
"fileGroup": RegistrationFileGroup.objects.get(name=f"Fichiers d'inscription - {establishment.name}"),
|
||||
"establishment": establishment,
|
||||
"status": fake.random_int(min=1, max=3)
|
||||
}
|
||||
|
||||
@ -467,7 +291,7 @@ class Command(BaseCommand):
|
||||
register_form.fees.set(fees)
|
||||
register_form.discounts.set(discounts)
|
||||
if not created:
|
||||
register_form.fileGroup = self.registration_file_group_1
|
||||
register_form.fileGroup = RegistrationFileGroup.objects.get(name=f"Fichiers d'inscription - {establishment.name}")
|
||||
register_form.save()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('50 RegistrationForms initialized or updated successfully'))
|
||||
Reference in New Issue
Block a user