mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Gestion multi-profil multi-école
This commit is contained in:
@ -1,14 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
from django.db.models.signals import post_migrate
|
||||
|
||||
def create_speciality(sender, **kwargs):
|
||||
from .models import Speciality
|
||||
if not Speciality.objects.filter(name='GROUPE').exists():
|
||||
Speciality.objects.create(name='GROUPE', color_code='#FF0000')
|
||||
|
||||
class SchoolConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'School'
|
||||
|
||||
def ready(self):
|
||||
post_migrate.connect(create_speciality, sender=self)
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
from Subscriptions.models import (
|
||||
RegistrationForm,
|
||||
Student,
|
||||
@ -10,9 +9,8 @@ from Subscriptions.models import (
|
||||
RegistrationTemplateMaster,
|
||||
RegistrationTemplate
|
||||
)
|
||||
from Auth.models import Profile
|
||||
from Auth.models import Profile, ProfileRole
|
||||
from School.models import (
|
||||
Establishment,
|
||||
FeeType,
|
||||
Speciality,
|
||||
Teacher,
|
||||
@ -20,8 +18,7 @@ from School.models import (
|
||||
PaymentMode,
|
||||
PaymentModeType,
|
||||
PaymentPlan,
|
||||
PaymentPlanType,
|
||||
StructureType,
|
||||
PaymentPlanType,
|
||||
DiscountType
|
||||
)
|
||||
from django.utils import timezone
|
||||
@ -34,6 +31,19 @@ from faker import Faker
|
||||
import random
|
||||
import json
|
||||
|
||||
from School.serializers import (
|
||||
FeeSerializer,
|
||||
DiscountSerializer,
|
||||
PaymentModeSerializer,
|
||||
PaymentPlanSerializer,
|
||||
SpecialitySerializer,
|
||||
TeacherSerializer,
|
||||
SchoolClassSerializer
|
||||
)
|
||||
from Auth.serializers import ProfileSerializer, ProfileRoleSerializer
|
||||
from Establishment.serializers import EstablishmentSerializer
|
||||
from Subscriptions.serializers import RegistrationFormSerializer, GuardianSerializer
|
||||
|
||||
# Définir le chemin vers le dossier mock_datas
|
||||
MOCK_DATAS_PATH = os.path.join(settings.BASE_DIR, 'School', 'management', 'mock_datas')
|
||||
|
||||
@ -41,176 +51,306 @@ class Command(BaseCommand):
|
||||
help = 'Initialise toutes les données mock'
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
self.create_or_update_establishments()
|
||||
self.create_or_update_fees()
|
||||
self.create_or_update_discounts()
|
||||
self.create_or_update_payment_modes()
|
||||
self.create_or_update_payment_plans()
|
||||
self.create_or_update_specialities()
|
||||
self.create_or_update_teachers()
|
||||
self.create_or_update_school_classes()
|
||||
self.create_or_update_registration_file_group()
|
||||
self.create_register_form()
|
||||
self.init_establishments()
|
||||
self.init_profiles()
|
||||
self.init_fees()
|
||||
self.init_discounts()
|
||||
self.init_payment_modes()
|
||||
self.init_payment_plans()
|
||||
self.init_specialities()
|
||||
self.init_teachers()
|
||||
self.init_guardians()
|
||||
self.init_school_classes()
|
||||
self.init_file_group()
|
||||
self.init_register_form()
|
||||
|
||||
def load_data(self, filename):
|
||||
with open(os.path.join(MOCK_DATAS_PATH, filename), 'r') as file:
|
||||
return json.load(file)
|
||||
|
||||
def create_or_update_establishments(self):
|
||||
def init_establishments(self):
|
||||
establishments_data = self.load_data('establishments.json')
|
||||
|
||||
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'))
|
||||
serializer = EstablishmentSerializer(data=establishment_data)
|
||||
if serializer.is_valid():
|
||||
establishment = serializer.save()
|
||||
self.establishments.append(establishment)
|
||||
self.stdout.write(self.style.SUCCESS(f'Establishment {establishment.name} created or updated successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS(f'Establishment {establishment.name} updated successfully'))
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for establishment: {serializer.errors}'))
|
||||
|
||||
def create_or_update_fees(self):
|
||||
def init_profiles(self):
|
||||
profiles_data = self.load_data('profiles.json')
|
||||
|
||||
for profile_data in profiles_data:
|
||||
# Randomize the number of roles to create (between 1 et 3)
|
||||
num_roles = random.randint(1, 3)
|
||||
selected_roles = []
|
||||
|
||||
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])
|
||||
|
||||
# Ensure no duplicate ADMIN role for the same establishment
|
||||
if role_type == ProfileRole.RoleType.PROFIL_ADMIN:
|
||||
if any(role['role_type'] == ProfileRole.RoleType.PROFIL_ADMIN and role['establishment'] == establishment.id for role in selected_roles):
|
||||
continue
|
||||
|
||||
selected_roles.append({
|
||||
"role_type": role_type,
|
||||
"establishment": establishment.id,
|
||||
"establishment_name": establishment.name
|
||||
})
|
||||
|
||||
# Generate email based on the selected roles and establishment
|
||||
role_types = '-'.join([f"{ProfileRole.RoleType(role['role_type']).name.replace('PROFIL_', '')}_{role['establishment_name'].replace(' ', '')}" for role in selected_roles])
|
||||
email = f"{profile_data['username']}-{role_types}@exemple.com"
|
||||
|
||||
# Add email to profile data
|
||||
profile_data['email'] = email
|
||||
|
||||
serializer = ProfileSerializer(data=profile_data)
|
||||
if serializer.is_valid():
|
||||
profile = serializer.save()
|
||||
profile.set_password(profile_data["password"])
|
||||
profile.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Profile {profile.email} created successfully'))
|
||||
|
||||
# Create or update the profile role for each selected role using ProfileRoleSerializer
|
||||
for role in selected_roles:
|
||||
role_data = {
|
||||
"profile": profile.id,
|
||||
"establishment": role["establishment"],
|
||||
"role_type": role["role_type"],
|
||||
"is_active": True
|
||||
}
|
||||
role_serializer = ProfileRoleSerializer(data=role_data)
|
||||
if role_serializer.is_valid():
|
||||
role_serializer.save()
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for profile role: {role_serializer.errors}'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for profile: {serializer.errors}'))
|
||||
|
||||
def init_fees(self):
|
||||
fees_data = self.load_data('fees.json')
|
||||
|
||||
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["establishment"] = establishment
|
||||
Fee.objects.update_or_create(
|
||||
name=fee_data["name"],
|
||||
type=fee_data["type"],
|
||||
defaults=fee_data
|
||||
)
|
||||
fee_data["establishment"] = establishment.id
|
||||
fee_data["type"] = random.choice([FeeType.REGISTRATION_FEE, FeeType.TUITION_FEE])
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Fees initialized or updated successfully'))
|
||||
serializer = FeeSerializer(data=fee_data)
|
||||
if serializer.is_valid():
|
||||
fee = serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Fee {fee.name} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for fee: {serializer.errors}'))
|
||||
|
||||
def create_or_update_discounts(self):
|
||||
def init_discounts(self):
|
||||
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"],
|
||||
discount_type=discount_data["discount_type"],
|
||||
defaults=discount_data
|
||||
)
|
||||
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])
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Discounts initialized or updated successfully'))
|
||||
serializer = DiscountSerializer(data=discount_data)
|
||||
if serializer.is_valid():
|
||||
discount = serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Discount {discount.name} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for discount: {serializer.errors}'))
|
||||
|
||||
def create_or_update_payment_modes(self):
|
||||
payment_modes_data = self.load_data('payment_modes.json')
|
||||
def init_payment_modes(self):
|
||||
modes = [PaymentModeType.SEPA, PaymentModeType.TRANSFER, PaymentModeType.CHECK, PaymentModeType.CASH]
|
||||
types = [FeeType.REGISTRATION_FEE, FeeType.TUITION_FEE]
|
||||
|
||||
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
|
||||
)
|
||||
for establishment in self.establishments:
|
||||
for mode in modes:
|
||||
for type in types:
|
||||
payment_mode_data = {
|
||||
"mode": mode,
|
||||
"type": type,
|
||||
"is_active": random.choice([True, False]),
|
||||
"establishment": establishment.id
|
||||
}
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Payment Modes initialized or updated successfully'))
|
||||
serializer = PaymentModeSerializer(data=payment_mode_data)
|
||||
if serializer.is_valid():
|
||||
payment_mode = serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Payment Mode {payment_mode} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for payment mode: {serializer.errors}'))
|
||||
|
||||
def create_or_update_payment_plans(self):
|
||||
payment_plans_data = self.load_data('payment_plans.json')
|
||||
def init_payment_plans(self):
|
||||
frequencies = [PaymentPlanType.ONE_TIME, PaymentPlanType.THREE_TIMES, PaymentPlanType.TEN_TIMES, PaymentPlanType.TWELVE_TIMES]
|
||||
types = [FeeType.REGISTRATION_FEE, FeeType.TUITION_FEE]
|
||||
current_date = timezone.now().date()
|
||||
|
||||
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)]
|
||||
for establishment in self.establishments:
|
||||
for frequency in frequencies:
|
||||
for type in types:
|
||||
payment_plan_data = {
|
||||
"frequency": frequency,
|
||||
"type": type,
|
||||
"is_active": random.choice([True, False]),
|
||||
"establishment": establishment.id,
|
||||
"due_dates": self.generate_due_dates(frequency, current_date)
|
||||
}
|
||||
|
||||
PaymentPlan.objects.update_or_create(
|
||||
frequency=payment_plan_data["frequency"],
|
||||
type=payment_plan_data["type"],
|
||||
defaults=payment_plan_data
|
||||
)
|
||||
serializer = PaymentPlanSerializer(data=payment_plan_data)
|
||||
if serializer.is_valid():
|
||||
payment_plan = serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Payment Plan {payment_plan} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for payment plan: {serializer.errors}'))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Payment Plans initialized or updated successfully'))
|
||||
def generate_due_dates(self, frequency, start_date):
|
||||
if frequency == PaymentPlanType.ONE_TIME:
|
||||
return [start_date + relativedelta(months=1)]
|
||||
elif frequency == PaymentPlanType.THREE_TIMES:
|
||||
return [start_date + relativedelta(months=1+4*i) for i in range(3)]
|
||||
elif frequency == PaymentPlanType.TEN_TIMES:
|
||||
return [start_date + relativedelta(months=1+i) for i in range(10)]
|
||||
elif frequency == PaymentPlanType.TWELVE_TIMES:
|
||||
return [start_date + relativedelta(months=1+i) for i in range(12)]
|
||||
|
||||
def create_or_update_specialities(self):
|
||||
def init_specialities(self):
|
||||
specialities_data = self.load_data('specialities.json')
|
||||
|
||||
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 = 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)
|
||||
speciality_data["name"] = f"{speciality_data['name']} - {establishment.name}"
|
||||
speciality_data["establishment"] = establishment.id
|
||||
|
||||
# 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,
|
||||
"establishment": establishment
|
||||
serializer = SpecialitySerializer(data=speciality_data)
|
||||
if serializer.is_valid():
|
||||
speciality = serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Speciality {speciality.name} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for speciality: {serializer.errors}'))
|
||||
|
||||
def init_teachers(self):
|
||||
fake = Faker()
|
||||
|
||||
# Récupérer tous les profils dont le role_type est soit ECOLE soit ADMIN
|
||||
profiles = Profile.objects.filter(roles__role_type__in=[ProfileRole.RoleType.PROFIL_ECOLE, ProfileRole.RoleType.PROFIL_ADMIN]).distinct()
|
||||
|
||||
for profile in profiles:
|
||||
# Récupérer les rôles associés au profil
|
||||
profile_roles = ProfileRole.objects.filter(profile=profile, role_type__in=[ProfileRole.RoleType.PROFIL_ECOLE, ProfileRole.RoleType.PROFIL_ADMIN])
|
||||
|
||||
for profile_role in profile_roles:
|
||||
establishment = profile_role.establishment
|
||||
teacher_data = {
|
||||
"last_name": fake.last_name(),
|
||||
"first_name": f"{fake.first_name()} - {establishment.name}",
|
||||
"profile_role": profile_role.id
|
||||
}
|
||||
)
|
||||
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()
|
||||
establishment_specialities = list(Speciality.objects.filter(establishment=establishment))
|
||||
num_specialities = min(random.randint(1, 3), len(establishment_specialities))
|
||||
selected_specialities = random.sample(establishment_specialities, num_specialities)
|
||||
|
||||
# Créer l'enseignant si il n'existe pas
|
||||
teacher_serializer = TeacherSerializer(data=teacher_data)
|
||||
if teacher_serializer.is_valid():
|
||||
teacher = teacher_serializer.save()
|
||||
# Associer les spécialités
|
||||
teacher.specialities.set(selected_specialities)
|
||||
teacher.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Teacher {teacher.last_name} created successfully for establishment {establishment.name}'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for teacher: {teacher_serializer.errors}'))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Teachers initialized or updated successfully'))
|
||||
|
||||
def create_or_update_school_classes(self):
|
||||
|
||||
def init_guardians(self):
|
||||
fake = Faker()
|
||||
|
||||
# Récupérer tous les profils dont le role_type est PROFIL_PARENT
|
||||
profiles = Profile.objects.filter(roles__role_type=ProfileRole.RoleType.PROFIL_PARENT).distinct()
|
||||
|
||||
for profile in profiles:
|
||||
# Récupérer les rôles associés au profil
|
||||
profile_roles = ProfileRole.objects.filter(profile=profile, role_type=ProfileRole.RoleType.PROFIL_PARENT)
|
||||
|
||||
for profile_role in profile_roles:
|
||||
establishment = profile_role.establishment
|
||||
guardian_data = {
|
||||
"last_name": fake.last_name(),
|
||||
"first_name": f"{fake.first_name()} - {establishment.name}",
|
||||
"profile_role": profile_role.id,
|
||||
"birth_date": fake.date_of_birth().strftime('%Y-%m-%d'), # Convertir en chaîne de caractères valide
|
||||
"address": fake.address(),
|
||||
"phone": fake.phone_number(),
|
||||
"profession": fake.job()
|
||||
}
|
||||
|
||||
# Créer le guardian si il n'existe pas
|
||||
guardian_serializer = GuardianSerializer(data=guardian_data)
|
||||
if guardian_serializer.is_valid():
|
||||
guardian = guardian_serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'Guardian {guardian.last_name} created successfully for establishment {establishment.name}'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for guardian: {guardian_serializer.errors}'))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Guardians initialized or updated successfully'))
|
||||
|
||||
def init_school_classes(self):
|
||||
school_classes_data = self.load_data('school_classes.json')
|
||||
|
||||
for index, class_data in enumerate(school_classes_data, start=1):
|
||||
teachers_ids = class_data.pop("teachers")
|
||||
# Randomize establishment
|
||||
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"],
|
||||
defaults=class_data
|
||||
)
|
||||
school_class.teachers.set(teachers_ids)
|
||||
school_class.save()
|
||||
class_data["establishment"] = establishment.id
|
||||
|
||||
# Randomize levels
|
||||
class_data["levels"] = random.sample(range(1, 10), random.randint(1, 5))
|
||||
|
||||
# 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]
|
||||
|
||||
# Use the serializer to create or update the school class
|
||||
class_data["teachers"] = teachers_ids
|
||||
serializer = SchoolClassSerializer(data=class_data)
|
||||
if serializer.is_valid():
|
||||
school_class = serializer.save()
|
||||
self.stdout.write(self.style.SUCCESS(f'SchoolClass {school_class.atmosphere_name} created or updated successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR(f'Error in data for school class: {serializer.errors}'))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('SchoolClasses initialized or updated successfully'))
|
||||
|
||||
def create_or_update_registration_file_group(self):
|
||||
file_groups_data = self.load_data('file_groups.json')
|
||||
def init_file_group(self):
|
||||
fake = Faker()
|
||||
|
||||
for group_data in file_groups_data:
|
||||
RegistrationFileGroup.objects.update_or_create(name=group_data["name"], defaults=group_data)
|
||||
self.stdout.write(self.style.SUCCESS(f'RegistrationFileGroup {group_data["name"]} initialized or updated successfully'))
|
||||
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}"
|
||||
description = fake.sentence()
|
||||
group_data = {
|
||||
"name": name,
|
||||
"description": description,
|
||||
"establishment": establishment
|
||||
}
|
||||
RegistrationFileGroup.objects.update_or_create(name=name, defaults=group_data)
|
||||
self.stdout.write(self.style.SUCCESS(f'RegistrationFileGroup {name} initialized or updated successfully'))
|
||||
|
||||
def create_register_form(self):
|
||||
self.stdout.write(self.style.SUCCESS('All RegistrationFileGroups initialized or updated successfully'))
|
||||
|
||||
def init_register_form(self):
|
||||
fake = Faker('fr_FR') # Utiliser le locale français pour Faker
|
||||
|
||||
file_group_count = RegistrationFileGroup.objects.count()
|
||||
@ -218,40 +358,13 @@ class Command(BaseCommand):
|
||||
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!",
|
||||
"establishment": establishment
|
||||
}
|
||||
|
||||
user, created = Profile.objects.update_or_create(
|
||||
email=profile_data["email"],
|
||||
defaults={
|
||||
"username": profile_data["username"],
|
||||
"email": profile_data["email"],
|
||||
"is_active": profile_data["is_active"],
|
||||
"droit": profile_data["droit"],
|
||||
"establishment": profile_data["establishment"]
|
||||
}
|
||||
)
|
||||
if created:
|
||||
user.set_password(profile_data["password"])
|
||||
user.save()
|
||||
|
||||
# Générer des données fictives pour le guardian
|
||||
guardian_data = {
|
||||
"associated_profile_id": user.id,
|
||||
"email": profile_data["email"],
|
||||
}
|
||||
# Récupérer un guardian aléatoire déjà créé
|
||||
guardian = Guardian.objects.order_by('?').first()
|
||||
|
||||
# Générer des données fictives pour l'étudiant
|
||||
student_data = {
|
||||
"last_name": f"{fake.last_name()} - {establishment.name}",
|
||||
"first_name": fake.first_name(),
|
||||
"last_name": fake.last_name(),
|
||||
"first_name": f"{fake.first_name()} - {establishment.name}",
|
||||
"address": fake.address(),
|
||||
"birth_date": fake.date_of_birth(),
|
||||
"birth_place": fake.city(),
|
||||
@ -261,16 +374,12 @@ class Command(BaseCommand):
|
||||
"level": fake.random_int(min=1, max=6)
|
||||
}
|
||||
|
||||
# Créer ou mettre à jour l'étudiant et le guardian
|
||||
# Créer ou mettre à jour l'étudiant
|
||||
student, created = Student.objects.get_or_create(
|
||||
last_name=student_data["last_name"],
|
||||
first_name=student_data["first_name"],
|
||||
defaults=student_data
|
||||
)
|
||||
guardian, created = Guardian.objects.get_or_create(
|
||||
last_name=guardian_data["email"],
|
||||
defaults=guardian_data
|
||||
)
|
||||
student.guardians.add(guardian)
|
||||
|
||||
# Récupérer les frais et les réductions
|
||||
@ -279,18 +388,23 @@ class Command(BaseCommand):
|
||||
|
||||
# Créer les données du formulaire d'inscription
|
||||
register_form_data = {
|
||||
"student": student,
|
||||
"fileGroup": RegistrationFileGroup.objects.get(id=fake.random_int(min=1, max=file_group_count)),
|
||||
"establishment": 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, defaults=register_form_data)
|
||||
register_form.fees.set(fees)
|
||||
register_form.discounts.set(discounts)
|
||||
if not created:
|
||||
register_form.fileGroup = file_group
|
||||
register_form.save()
|
||||
register_form, created = RegistrationForm.objects.get_or_create(
|
||||
student=student,
|
||||
establishment=establishment,
|
||||
defaults=register_form_data
|
||||
)
|
||||
|
||||
if created:
|
||||
register_form.fees.set(fees)
|
||||
register_form.discounts.set(discounts)
|
||||
self.stdout.write(self.style.SUCCESS(f'RegistrationForm for student {student.last_name} created successfully'))
|
||||
else:
|
||||
self.stdout.write(self.style.SUCCESS(f'RegistrationForm for student {student.last_name} already exists'))
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('50 RegistrationForms initialized or updated successfully'))
|
||||
@ -2,15 +2,41 @@
|
||||
{
|
||||
"name": "Parrainage",
|
||||
"amount": "10.00",
|
||||
"description": "Réduction pour parrainage",
|
||||
"discount_type": 1,
|
||||
"type": 1
|
||||
"description": "Réduction pour parrainage"
|
||||
},
|
||||
{
|
||||
"name": "Réinscription",
|
||||
"amount": "100.00",
|
||||
"description": "Réduction pour Réinscription",
|
||||
"discount_type": 1,
|
||||
"type": 0
|
||||
"description": "Réduction pour Réinscription"
|
||||
},
|
||||
{
|
||||
"name": "Famille nombreuse",
|
||||
"amount": "50.00",
|
||||
"description": "Réduction pour les familles nombreuses"
|
||||
},
|
||||
{
|
||||
"name": "Excellence académique",
|
||||
"amount": "200.00",
|
||||
"description": "Réduction pour les élèves ayant des résultats académiques exceptionnels"
|
||||
},
|
||||
{
|
||||
"name": "Sportif de haut niveau",
|
||||
"amount": "150.00",
|
||||
"description": "Réduction pour les élèves pratiquant un sport de haut niveau"
|
||||
},
|
||||
{
|
||||
"name": "Artiste talentueux",
|
||||
"amount": "100.00",
|
||||
"description": "Réduction pour les élèves ayant des talents artistiques"
|
||||
},
|
||||
{
|
||||
"name": "Bourse d'études",
|
||||
"amount": "300.00",
|
||||
"description": "Réduction pour les élèves bénéficiant d'une bourse d'études"
|
||||
},
|
||||
{
|
||||
"name": "Réduction spéciale",
|
||||
"amount": "75.00",
|
||||
"description": "Réduction spéciale pour des occasions particulières"
|
||||
}
|
||||
]
|
||||
@ -3,35 +3,30 @@
|
||||
"name": "Frais d'inscription",
|
||||
"base_amount": "150.00",
|
||||
"description": "Montant de base",
|
||||
"is_active": true,
|
||||
"type": 0
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"name": "Matériel",
|
||||
"base_amount": "85.00",
|
||||
"description": "Livres / jouets",
|
||||
"is_active": true,
|
||||
"type": 0
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"name": "Sorties périscolaires",
|
||||
"base_amount": "120.00",
|
||||
"description": "Sorties",
|
||||
"is_active": true,
|
||||
"type": 0
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"name": "Les colibris",
|
||||
"base_amount": "4500.00",
|
||||
"description": "TPS / PS / MS / GS",
|
||||
"is_active": true,
|
||||
"type": 1
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"name": "Les butterflies",
|
||||
"base_amount": "5000.00",
|
||||
"description": "CP / CE1 / CE2 / CM1 / CM2",
|
||||
"is_active": true,
|
||||
"type": 1
|
||||
"is_active": true
|
||||
}
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
[
|
||||
{
|
||||
"name": "Fichiers d'inscription - Classe 1 - Ecole A",
|
||||
"description": "Fichiers d'inscription pour la Classe 1 de l'école Ecole A"
|
||||
},
|
||||
{
|
||||
"name": "Fichiers d'inscription - Classe 2 - Ecole B",
|
||||
"description": "Fichiers d'inscription pour la Classe 2 de l'école Ecole B"
|
||||
},
|
||||
{
|
||||
"name": "Fichiers d'inscription - Classe 3 - Ecole C",
|
||||
"description": "Fichiers d'inscription pour la Classe 3 de l'école Ecole C"
|
||||
},
|
||||
{
|
||||
"name": "Fichiers d'inscription - Classe 4 - Ecole A",
|
||||
"description": "Fichiers d'inscription pour la Classe 4 de l'école Ecole A"
|
||||
},
|
||||
{
|
||||
"name": "Fichiers d'inscription - Classe 5 - Ecole B",
|
||||
"description": "Fichiers d'inscription pour la Classe 5 de l'école Ecole B"
|
||||
}
|
||||
]
|
||||
@ -1,12 +0,0 @@
|
||||
[
|
||||
{
|
||||
"mode": 4,
|
||||
"type": 0,
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"mode": 2,
|
||||
"type": 1,
|
||||
"is_active": true
|
||||
}
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
[
|
||||
{
|
||||
"frequency": 1,
|
||||
"type": 0,
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"frequency": 3,
|
||||
"type": 1,
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"frequency": 10,
|
||||
"type": 1,
|
||||
"is_active": true
|
||||
},
|
||||
{
|
||||
"frequency": 12,
|
||||
"type": 1,
|
||||
"is_active": true
|
||||
}
|
||||
]
|
||||
34
Back-End/School/management/mock_datas/profiles.json
Normal file
34
Back-End/School/management/mock_datas/profiles.json
Normal file
@ -0,0 +1,34 @@
|
||||
[
|
||||
{
|
||||
"username": "albus.dumbledore",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "severus.rogue",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "minerva.mcgonagall",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "pomona.chourave",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "rubeus.hagrid",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "filius.flitwick",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "pomona.sprout",
|
||||
"password": "Provisoire01!"
|
||||
},
|
||||
{
|
||||
"username": "aurora.sinistra",
|
||||
"password": "Provisoire01!"
|
||||
}
|
||||
]
|
||||
@ -7,8 +7,7 @@
|
||||
"levels": [2, 3, 4],
|
||||
"type": 1,
|
||||
"time_range": ["08:30", "17:30"],
|
||||
"opening_days": [1, 2, 4, 5],
|
||||
"teachers": [2]
|
||||
"opening_days": [1, 2, 4, 5]
|
||||
},
|
||||
{
|
||||
"age_range": "2-3",
|
||||
@ -18,8 +17,7 @@
|
||||
"levels": [1],
|
||||
"type": 1,
|
||||
"time_range": ["08:30", "17:30"],
|
||||
"opening_days": [1, 2, 4, 5],
|
||||
"teachers": [3]
|
||||
"opening_days": [1, 2, 4, 5]
|
||||
},
|
||||
{
|
||||
"age_range": "6-12",
|
||||
@ -29,8 +27,7 @@
|
||||
"levels": [5, 6, 7, 8, 9],
|
||||
"type": 1,
|
||||
"time_range": ["08:30", "17:30"],
|
||||
"opening_days": [1, 2, 4, 5],
|
||||
"teachers": [4]
|
||||
"opening_days": [1, 2, 4, 5]
|
||||
},
|
||||
{
|
||||
"age_range": "4-6",
|
||||
@ -40,8 +37,7 @@
|
||||
"levels": [4, 5],
|
||||
"type": 1,
|
||||
"time_range": ["08:30", "17:30"],
|
||||
"opening_days": [1, 2, 4, 5],
|
||||
"teachers": [1]
|
||||
"opening_days": [1, 2, 4, 5]
|
||||
},
|
||||
{
|
||||
"age_range": "7-9",
|
||||
@ -51,7 +47,6 @@
|
||||
"levels": [6, 7],
|
||||
"type": 1,
|
||||
"time_range": ["08:30", "17:30"],
|
||||
"opening_days": [1, 2, 4, 5],
|
||||
"teachers": [2]
|
||||
"opening_days": [1, 2, 4, 5]
|
||||
}
|
||||
]
|
||||
@ -1,58 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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": 2
|
||||
},
|
||||
{
|
||||
"last_name": "MC GONAGALL",
|
||||
"first_name": "Minerva",
|
||||
"email": "minerva.mcgonagall@gmail.com",
|
||||
"specialities": ["MATHS", "HISTOIRE"],
|
||||
"droit": 2
|
||||
},
|
||||
{
|
||||
"last_name": "CHOURAVE",
|
||||
"first_name": "Pomona",
|
||||
"email": "pomona.chourave@gmail.com",
|
||||
"specialities": ["MATHS", "FRANCAIS", "SPORT"],
|
||||
"droit": 1
|
||||
},
|
||||
{
|
||||
"last_name": "HAGRID",
|
||||
"first_name": "Rubeus",
|
||||
"email": "rubeus.hagrid@gmail.com",
|
||||
"specialities": ["SCIENCES"],
|
||||
"droit": 2
|
||||
},
|
||||
{
|
||||
"last_name": "FLITWICK",
|
||||
"first_name": "Filius",
|
||||
"email": "filius.flitwick@gmail.com",
|
||||
"specialities": ["MUSIQUE"],
|
||||
"droit": 1
|
||||
},
|
||||
{
|
||||
"last_name": "SPROUT",
|
||||
"first_name": "Pomona",
|
||||
"email": "pomona.sprout@gmail.com",
|
||||
"specialities": ["ART"],
|
||||
"droit": 2
|
||||
},
|
||||
{
|
||||
"last_name": "SINISTRA",
|
||||
"first_name": "Aurora",
|
||||
"email": "aurora.sinistra@gmail.com",
|
||||
"specialities": ["INFORMATIQUE"],
|
||||
"droit": 2
|
||||
}
|
||||
]
|
||||
@ -1,5 +1,6 @@
|
||||
from django.db import models
|
||||
from Auth.models import Profile
|
||||
from Auth.models import ProfileRole
|
||||
from Establishment.models import Establishment
|
||||
from django.db.models import JSONField
|
||||
from django.dispatch import receiver
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
@ -18,27 +19,11 @@ LEVEL_CHOICES = [
|
||||
(9, 'Cours Moyen 2 (CM2)')
|
||||
]
|
||||
|
||||
class StructureType(models.IntegerChoices):
|
||||
MATERNELLE = 1, _('Maternelle')
|
||||
PRIMAIRE = 2, _('Primaire')
|
||||
SECONDAIRE = 3, _('Secondaire')
|
||||
|
||||
class Establishment(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
address = models.CharField(max_length=255)
|
||||
total_capacity = models.IntegerField()
|
||||
establishment_type = ArrayField(models.IntegerField(choices=StructureType.choices))
|
||||
licence_code = models.CharField(max_length=100, blank=True)
|
||||
is_active = models.BooleanField(default=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Speciality(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
updated_date = models.DateTimeField(auto_now=True)
|
||||
color_code = models.CharField(max_length=7, default='#FFFFFF')
|
||||
establishment = models.ForeignKey(Establishment, on_delete=models.CASCADE, related_name='specialities')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@ -46,9 +31,8 @@ class Speciality(models.Model):
|
||||
class Teacher(models.Model):
|
||||
last_name = models.CharField(max_length=100)
|
||||
first_name = models.CharField(max_length=100)
|
||||
email = models.EmailField(unique=True)
|
||||
specialities = models.ManyToManyField(Speciality, blank=True)
|
||||
associated_profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True, blank=True)
|
||||
profile_role = models.OneToOneField(ProfileRole, on_delete=models.CASCADE, related_name='teacher_profile', null=True, blank=True)
|
||||
updated_date = models.DateTimeField(auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Teacher, Speciality, SchoolClass, Planning, LEVEL_CHOICES, Discount, Fee, PaymentPlan, PaymentMode, Establishment
|
||||
from Auth.models import Profile
|
||||
from .models import Teacher, Speciality, SchoolClass, Planning, LEVEL_CHOICES, Discount, Fee, PaymentPlan, PaymentMode
|
||||
from Auth.models import Profile, ProfileRole
|
||||
from Subscriptions.models import Student
|
||||
from Establishment.models import Establishment
|
||||
from N3wtSchool import settings, bdd
|
||||
from django.utils import timezone
|
||||
import pytz
|
||||
@ -30,9 +31,10 @@ class TeacherDetailSerializer(serializers.ModelSerializer):
|
||||
class TeacherSerializer(serializers.ModelSerializer):
|
||||
specialities = serializers.PrimaryKeyRelatedField(queryset=Speciality.objects.all(), many=True, required=False)
|
||||
specialities_details = serializers.SerializerMethodField()
|
||||
associated_profile = serializers.PrimaryKeyRelatedField(queryset=Profile.objects.all(), required=True)
|
||||
profile_role = serializers.PrimaryKeyRelatedField(queryset=ProfileRole.objects.all(), required=True)
|
||||
updated_date_formatted = serializers.SerializerMethodField()
|
||||
droit = serializers.SerializerMethodField()
|
||||
role_type = serializers.SerializerMethodField()
|
||||
associated_profile_email = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = Teacher
|
||||
@ -40,12 +42,12 @@ class TeacherSerializer(serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
specialities_data = validated_data.pop('specialities', None)
|
||||
associated_profile = validated_data.pop('associated_profile', None)
|
||||
profile_role = validated_data.pop('profile_role', None)
|
||||
teacher = Teacher.objects.create(**validated_data)
|
||||
if specialities_data:
|
||||
teacher.specialities.set(specialities_data)
|
||||
if associated_profile:
|
||||
teacher.associated_profile = associated_profile
|
||||
if profile_role:
|
||||
teacher.profile_role = profile_role
|
||||
teacher.save()
|
||||
return teacher
|
||||
|
||||
@ -54,7 +56,7 @@ class TeacherSerializer(serializers.ModelSerializer):
|
||||
instance.last_name = validated_data.get('last_name', instance.last_name)
|
||||
instance.first_name = validated_data.get('first_name', instance.first_name)
|
||||
instance.email = validated_data.get('email', instance.email)
|
||||
instance.associated_profile = validated_data.get('associated_profile', instance.associated_profile)
|
||||
instance.profile_role = validated_data.get('profile_role', instance.profile_role)
|
||||
instance.save()
|
||||
if specialities_data:
|
||||
instance.specialities.set(specialities_data)
|
||||
@ -64,17 +66,18 @@ class TeacherSerializer(serializers.ModelSerializer):
|
||||
utc_time = timezone.localtime(obj.updated_date) # Convert to local time
|
||||
local_tz = pytz.timezone(settings.TZ_APPLI)
|
||||
local_time = utc_time.astimezone(local_tz)
|
||||
|
||||
return local_time.strftime("%d-%m-%Y %H:%M")
|
||||
|
||||
def get_droit(self, obj):
|
||||
if obj.associated_profile:
|
||||
return obj.associated_profile.droit
|
||||
return None
|
||||
def get_role_type(self, obj):
|
||||
profile_role = obj.profile_role
|
||||
return {'role_type': profile_role.role_type, 'establishment': profile_role.establishment.name}
|
||||
|
||||
def get_specialities_details(self, obj):
|
||||
return [{'id': speciality.id, 'name': speciality.name, 'color_code': speciality.color_code} for speciality in obj.specialities.all()]
|
||||
|
||||
def get_associated_profile_email(self, obj):
|
||||
return obj.profile_role.profile.email
|
||||
|
||||
class PlanningSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Planning
|
||||
@ -207,9 +210,4 @@ class PaymentPlanSerializer(serializers.ModelSerializer):
|
||||
class PaymentModeSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = PaymentMode
|
||||
fields = '__all__'
|
||||
|
||||
class EstablishmentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Establishment
|
||||
fields = '__all__'
|
||||
@ -16,9 +16,7 @@ from .views import (
|
||||
PaymentPlanListCreateView,
|
||||
PaymentPlanDetailView,
|
||||
PaymentModeListCreateView,
|
||||
PaymentModeDetailView,
|
||||
EstablishmentListCreateView,
|
||||
EstablishmentDetailView
|
||||
PaymentModeDetailView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
@ -44,8 +42,5 @@ urlpatterns = [
|
||||
re_path(r'^paymentPlans/(?P<id>[0-9]+)$', PaymentPlanDetailView.as_view(), name="payment_plan_detail"),
|
||||
|
||||
re_path(r'^paymentModes$', PaymentModeListCreateView.as_view(), name="payment_mode_list_create"),
|
||||
re_path(r'^paymentModes/(?P<id>[0-9]+)$', PaymentModeDetailView.as_view(), name="payment_mode_detail"),
|
||||
|
||||
re_path(r'^establishments$', EstablishmentListCreateView.as_view(), name='establishment_list_create'),
|
||||
re_path(r'^establishments/(?P<id>[0-9]+)$', EstablishmentDetailView.as_view(), name="establishment_detail"),
|
||||
re_path(r'^paymentModes/(?P<id>[0-9]+)$', PaymentModeDetailView.as_view(), name="payment_mode_detail")
|
||||
]
|
||||
@ -12,8 +12,7 @@ from .models import (
|
||||
Discount,
|
||||
Fee,
|
||||
PaymentPlan,
|
||||
PaymentMode,
|
||||
Establishment
|
||||
PaymentMode
|
||||
)
|
||||
from .serializers import (
|
||||
TeacherSerializer,
|
||||
@ -23,8 +22,7 @@ from .serializers import (
|
||||
DiscountSerializer,
|
||||
FeeSerializer,
|
||||
PaymentPlanSerializer,
|
||||
PaymentModeSerializer,
|
||||
EstablishmentSerializer
|
||||
PaymentModeSerializer
|
||||
)
|
||||
from N3wtSchool.bdd import delete_object, getAllObjects, getObject
|
||||
|
||||
@ -32,8 +30,14 @@ from N3wtSchool.bdd import delete_object, getAllObjects, getObject
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class SpecialityListCreateView(APIView):
|
||||
def get(self, request):
|
||||
specialitiesList = getAllObjects(Speciality)
|
||||
specialities_serializer = SpecialitySerializer(specialitiesList, many=True)
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
specialities_list = getAllObjects(Speciality)
|
||||
if establishment_id:
|
||||
specialities_list = specialities_list.filter(establishment__id=establishment_id).distinct()
|
||||
specialities_serializer = SpecialitySerializer(specialities_list, many=True)
|
||||
return JsonResponse(specialities_serializer.data, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
@ -51,7 +55,7 @@ class SpecialityListCreateView(APIView):
|
||||
class SpecialityDetailView(APIView):
|
||||
def get(self, request, id):
|
||||
speciality = getObject(_objectName=Speciality, _columnName='id', _value=id)
|
||||
speciality_serializer = SpecialitySerializer(speciality)
|
||||
speciality_serializer=SpecialitySerializer(speciality)
|
||||
return JsonResponse(speciality_serializer.data, safe=False)
|
||||
|
||||
def put(self, request, id):
|
||||
@ -71,9 +75,14 @@ class SpecialityDetailView(APIView):
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class TeacherListCreateView(APIView):
|
||||
def get(self, request):
|
||||
teachersList=getAllObjects(Teacher)
|
||||
teachers_serializer=TeacherSerializer(teachersList, many=True)
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
teachers_list = getAllObjects(Teacher)
|
||||
if teachers_list:
|
||||
teachers_list = teachers_list.filter(profile_role__establishment_id=establishment_id)
|
||||
teachers_serializer = TeacherSerializer(teachers_list, many=True)
|
||||
return JsonResponse(teachers_serializer.data, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
@ -107,14 +116,20 @@ class TeacherDetailView(APIView):
|
||||
return JsonResponse(teacher_serializer.errors, safe=False)
|
||||
|
||||
def delete(self, request, id):
|
||||
return delete_object(Teacher, id, related_field='associated_profile')
|
||||
return delete_object(Teacher, id, related_field='profile')
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class SchoolClassListCreateView(APIView):
|
||||
def get(self, request):
|
||||
classesList=getAllObjects(SchoolClass)
|
||||
classes_serializer=SchoolClassSerializer(classesList, many=True)
|
||||
def get(self, request):
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
school_classes_list = getAllObjects(SchoolClass)
|
||||
if school_classes_list:
|
||||
school_classes_list = school_classes_list.filter(establishment=establishment_id).distinct()
|
||||
classes_serializer = SchoolClassSerializer(school_classes_list, many=True)
|
||||
return JsonResponse(classes_serializer.data, safe=False)
|
||||
|
||||
def post(self, request):
|
||||
@ -201,9 +216,14 @@ class PlanningDetailView(APIView):
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class FeeListCreateView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
filter = request.GET.get('filter', '').strip()
|
||||
fee_type_value = 0 if filter == 'registration' else 1
|
||||
fees = Fee.objects.filter(type=fee_type_value)
|
||||
|
||||
fees = Fee.objects.filter(type=fee_type_value, establishment_id=establishment_id).distinct()
|
||||
fee_serializer = FeeSerializer(fees, many=True)
|
||||
|
||||
return JsonResponse(fee_serializer.data, safe=False, status=status.HTTP_200_OK)
|
||||
@ -244,11 +264,16 @@ class FeeDetailView(APIView):
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class DiscountListCreateView(APIView):
|
||||
class DiscountListCreateView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
filter = request.GET.get('filter', '').strip()
|
||||
discount_type_value = 0 if filter == 'registration' else 1
|
||||
discounts = Discount.objects.filter(type=discount_type_value)
|
||||
|
||||
discounts = Discount.objects.filter(type=discount_type_value, establishment_id=establishment_id).distinct()
|
||||
discounts_serializer = DiscountSerializer(discounts, many=True)
|
||||
|
||||
return JsonResponse(discounts_serializer.data, safe=False, status=status.HTTP_200_OK)
|
||||
@ -291,10 +316,15 @@ class DiscountDetailView(APIView):
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class PaymentPlanListCreateView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
filter = request.GET.get('filter', '').strip()
|
||||
type_value = 0 if filter == 'registration' else 1
|
||||
paymentPlans = PaymentPlan.objects.filter(type=type_value)
|
||||
payment_plans_serializer = PaymentPlanSerializer(paymentPlans, many=True)
|
||||
|
||||
payment_plans = PaymentPlan.objects.filter(type=type_value, establishment_id=establishment_id).distinct()
|
||||
payment_plans_serializer = PaymentPlanSerializer(payment_plans, many=True)
|
||||
|
||||
return JsonResponse(payment_plans_serializer.data, safe=False, status=status.HTTP_200_OK)
|
||||
|
||||
@ -336,10 +366,15 @@ class PaymentPlanDetailView(APIView):
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class PaymentModeListCreateView(APIView):
|
||||
def get(self, request):
|
||||
establishment_id = request.GET.get('establishment_id', None)
|
||||
if establishment_id is None:
|
||||
return JsonResponse({'error': 'establishment_id est requis'}, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
filter = request.GET.get('filter', '').strip()
|
||||
type_value = 0 if filter == 'registration' else 1
|
||||
paymentModes = PaymentMode.objects.filter(type=type_value)
|
||||
payment_modes_serializer = PaymentModeSerializer(paymentModes, many=True)
|
||||
|
||||
payment_modes = PaymentMode.objects.filter(type=type_value, establishment_id=establishment_id).distinct()
|
||||
payment_modes_serializer = PaymentModeSerializer(payment_modes, many=True)
|
||||
|
||||
return JsonResponse(payment_modes_serializer.data, safe=False, status=status.HTTP_200_OK)
|
||||
|
||||
@ -376,45 +411,3 @@ class PaymentModeDetailView(APIView):
|
||||
|
||||
def delete(self, request, id):
|
||||
return delete_object(PaymentMode, id)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class EstablishmentListCreateView(APIView):
|
||||
def get(self, request):
|
||||
establishments=getAllObjects(Establishment)
|
||||
establishments_serializer=EstablishmentSerializer(establishments, many=True)
|
||||
return JsonResponse(establishments_serializer.data, safe=False, status=status.HTTP_200_OK)
|
||||
|
||||
def post(self, request):
|
||||
establishment_data = JSONParser().parse(request)
|
||||
establishment_serializer = EstablishmentSerializer(data=establishment_data)
|
||||
if establishment_serializer.is_valid():
|
||||
establishment_serializer.save()
|
||||
return JsonResponse(establishment_serializer.data, safe=False, status=status.HTTP_201_CREATED)
|
||||
return JsonResponse(establishment_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@method_decorator(csrf_protect, name='dispatch')
|
||||
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
||||
class EstablishmentDetailView(APIView):
|
||||
def get(self, request, id=None):
|
||||
try:
|
||||
establishment = Establishment.objects.get(id=id)
|
||||
establishment_serializer = EstablishmentSerializer(establishment)
|
||||
return JsonResponse(establishment_serializer.data, safe=False)
|
||||
except Establishment.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
def put(self, request, id):
|
||||
establishment_data = JSONParser().parse(request)
|
||||
try:
|
||||
establishment = Establishment.objects.get(id=id)
|
||||
except Establishment.DoesNotExist:
|
||||
return JsonResponse({'error': 'No object found'}, status=status.HTTP_404_NOT_FOUND)
|
||||
establishment_serializer = EstablishmentSerializer(establishment, data=establishment_data, partial=True)
|
||||
if establishment_serializer.is_valid():
|
||||
establishment_serializer.save()
|
||||
return JsonResponse(establishment_serializer.data, safe=False)
|
||||
return JsonResponse(establishment_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def delete(self, request, id):
|
||||
return delete_object(Establishment, id)
|
||||
Reference in New Issue
Block a user