mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Création d'un annuaire / mise à jour du subscribe
This commit is contained in:
@ -103,20 +103,26 @@ class Command(BaseCommand):
|
||||
|
||||
# Créer entre 1 et 3 ProfileRole pour chaque profil
|
||||
num_roles = random.randint(1, 3)
|
||||
created_roles = set()
|
||||
for _ in range(num_roles):
|
||||
establishment = random.choice(self.establishments)
|
||||
role_type = random.choice([ProfileRole.RoleType.PROFIL_ECOLE, ProfileRole.RoleType.PROFIL_ADMIN, ProfileRole.RoleType.PROFIL_PARENT])
|
||||
|
||||
# Vérifier si le rôle existe déjà pour cet établissement
|
||||
if (establishment.id, role_type) in created_roles:
|
||||
continue
|
||||
|
||||
profile_role_data = {
|
||||
"profile": profile.id,
|
||||
"establishment": establishment.id,
|
||||
"role_type": role_type,
|
||||
"is_active": True
|
||||
"is_active": random.choice([True, False])
|
||||
}
|
||||
|
||||
profile_role_serializer = ProfileRoleSerializer(data=profile_role_data)
|
||||
if profile_role_serializer.is_valid():
|
||||
profile_role_serializer.save()
|
||||
created_roles.add((establishment.id, role_type))
|
||||
self.stdout.write(self.style.SUCCESS(f'ProfileRole for {profile.email} created successfully with role type {role_type}'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for profile role: {profile_role_serializer.errors}'))
|
||||
@ -129,7 +135,7 @@ class Command(BaseCommand):
|
||||
for fee_data in fees_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
print(f'establishment : {establishment}')
|
||||
fee_data["name"] = f"{fee_data['name']} - {establishment.name}"
|
||||
fee_data["name"] = fee_data['name']
|
||||
fee_data["establishment"] = establishment.id
|
||||
fee_data["type"] = random.choice([FeeType.REGISTRATION_FEE, FeeType.TUITION_FEE])
|
||||
|
||||
@ -145,7 +151,7 @@ class Command(BaseCommand):
|
||||
|
||||
for discount_data in discounts_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
discount_data["name"] = f"{discount_data['name']} - {establishment.name}"
|
||||
discount_data["name"] = discount_data['name']
|
||||
discount_data["establishment"] = establishment.id
|
||||
discount_data["type"] = random.choice([FeeType.REGISTRATION_FEE, FeeType.TUITION_FEE])
|
||||
discount_data["discount_type"] = random.choice([DiscountType.CURRENCY, DiscountType.PERCENT])
|
||||
@ -216,7 +222,7 @@ class Command(BaseCommand):
|
||||
|
||||
for speciality_data in specialities_data:
|
||||
establishment = random.choice(self.establishments)
|
||||
speciality_data["name"] = f"{speciality_data['name']} - {establishment.name}"
|
||||
speciality_data["name"] = speciality_data['name']
|
||||
speciality_data["establishment"] = establishment.id
|
||||
|
||||
serializer = SpecialitySerializer(data=speciality_data)
|
||||
@ -260,7 +266,7 @@ class Command(BaseCommand):
|
||||
# Générer des données fictives pour l'enseignant
|
||||
teacher_data = {
|
||||
"last_name": fake.last_name(),
|
||||
"first_name": f"{fake.first_name()} - {profile_role.establishment.name}",
|
||||
"first_name": fake.first_name(),
|
||||
"profile_role": profile_role.id
|
||||
}
|
||||
|
||||
@ -287,7 +293,7 @@ class Command(BaseCommand):
|
||||
for index, class_data in enumerate(school_classes_data, start=1):
|
||||
# Randomize establishment
|
||||
establishment = random.choice(self.establishments)
|
||||
class_data["atmosphere_name"] = f"Classe {index} - {establishment.name}"
|
||||
class_data["atmosphere_name"] = f"Classe {index}"
|
||||
class_data["establishment"] = establishment.id
|
||||
|
||||
# Randomize levels
|
||||
@ -295,9 +301,12 @@ class Command(BaseCommand):
|
||||
|
||||
# Randomize teachers
|
||||
establishment_teachers = list(Teacher.objects.filter(profile_role__establishment=establishment))
|
||||
num_teachers = min(random.randint(1, 10), len(establishment_teachers))
|
||||
selected_teachers = random.sample(establishment_teachers, num_teachers)
|
||||
teachers_ids = [teacher.id for teacher in selected_teachers]
|
||||
if len(establishment_teachers) > 0:
|
||||
num_teachers = min(2, len(establishment_teachers))
|
||||
selected_teachers = random.sample(establishment_teachers, num_teachers)
|
||||
teachers_ids = [teacher.id for teacher in selected_teachers]
|
||||
else:
|
||||
teachers_ids = []
|
||||
|
||||
# Use the serializer to create or update the school class
|
||||
class_data["teachers"] = teachers_ids
|
||||
@ -315,7 +324,7 @@ class Command(BaseCommand):
|
||||
|
||||
for establishment in self.establishments:
|
||||
for i in range(1, 4): # Créer 3 groupes de fichiers par établissement
|
||||
name = f"Fichiers d'inscription - {fake.word()} - {establishment.name}"
|
||||
name = f"Fichiers d'inscription - {fake.word()}"
|
||||
description = fake.sentence()
|
||||
group_data = {
|
||||
"name": name,
|
||||
@ -342,8 +351,6 @@ class Command(BaseCommand):
|
||||
used_profiles = set()
|
||||
|
||||
for _ in range(50):
|
||||
establishment = random.choice(self.establishments)
|
||||
|
||||
# Récupérer un profil aléatoire qui n'a pas encore été utilisé
|
||||
available_profiles = profiles_with_parent_role.exclude(id__in=used_profiles)
|
||||
if not available_profiles.exists():
|
||||
@ -354,7 +361,8 @@ class Command(BaseCommand):
|
||||
used_profiles.add(profile.id)
|
||||
|
||||
# Récupérer le ProfileRole Parent associé au profil
|
||||
profile_role = ProfileRole.objects.filter(profile=profile, role_type=ProfileRole.RoleType.PROFIL_PARENT).first()
|
||||
profile_roles = ProfileRole.objects.filter(profile=profile, role_type=ProfileRole.RoleType.PROFIL_PARENT)
|
||||
profile_role = random.choice(profile_roles)
|
||||
|
||||
# Générer des données fictives pour le guardian
|
||||
guardian_data = {
|
||||
@ -370,7 +378,7 @@ class Command(BaseCommand):
|
||||
# Générer des données fictives pour l'étudiant
|
||||
student_data = {
|
||||
"last_name": fake.last_name(),
|
||||
"first_name": f"{fake.first_name()} - {establishment.name}",
|
||||
"first_name": fake.first_name(),
|
||||
"address": fake.address(),
|
||||
"birth_date": fake.date_of_birth(),
|
||||
"birth_place": fake.city(),
|
||||
@ -398,14 +406,14 @@ class Command(BaseCommand):
|
||||
# Créer les données du formulaire d'inscription
|
||||
register_form_data = {
|
||||
"fileGroup": RegistrationFileGroup.objects.get(id=fake.random_int(min=1, max=file_group_count)),
|
||||
"establishment": establishment,
|
||||
"establishment": profile_role.establishment,
|
||||
"status": fake.random_int(min=1, max=3)
|
||||
}
|
||||
|
||||
# Créer ou mettre à jour le formulaire d'inscription
|
||||
register_form, created = RegistrationForm.objects.get_or_create(
|
||||
student=student,
|
||||
establishment=establishment,
|
||||
establishment=profile_role.establishment,
|
||||
defaults=register_form_data
|
||||
)
|
||||
|
||||
|
||||
@ -49,7 +49,9 @@ class TeacherSerializer(serializers.ModelSerializer):
|
||||
|
||||
if profile_role_data:
|
||||
establishment_id = profile_role_data.pop('establishment').id
|
||||
profile_id = profile_role_data.pop('profile').id
|
||||
profile_role_data['establishment'] = establishment_id
|
||||
profile_role_data['profile'] = profile_id
|
||||
|
||||
# Créer l'instance de ProfileRole
|
||||
profile_role_serializer = ProfileRoleSerializer(data=profile_role_data)
|
||||
@ -95,7 +97,9 @@ class TeacherSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_role_type(self, obj):
|
||||
profile_role = obj.profile_role
|
||||
return {'role_type': profile_role.role_type, 'establishment': profile_role.establishment.name}
|
||||
if profile_role:
|
||||
return {'role_type': profile_role.role_type, 'establishment': profile_role.establishment.name}
|
||||
return None
|
||||
|
||||
def get_specialities_details(self, obj):
|
||||
return [{'id': speciality.id, 'name': speciality.name, 'color_code': speciality.color_code} for speciality in obj.specialities.all()]
|
||||
|
||||
Reference in New Issue
Block a user