feat: Gestion de la création d'un nouveau guardian, de l'association

avec un guardian dumême établissement, et de l'association avec un
guardian d'un autre établissement
This commit is contained in:
N3WT DE COMPET
2025-03-18 21:06:44 +01:00
parent 173ac47fb2
commit fb73f9e9a8
11 changed files with 277 additions and 181 deletions

View File

@ -16,7 +16,24 @@ class ProfileSerializer(serializers.ModelSerializer):
def get_roles(self, obj):
roles = ProfileRole.objects.filter(profile=obj)
return [{'role_type': role.role_type, 'establishment': role.establishment.id, 'establishment_name': role.establishment.name, 'is_active': role.is_active} for role in roles]
roles_data = []
for role in roles:
# Récupérer l'ID de l'associated_person en fonction du type de rôle
if role.role_type == ProfileRole.RoleType.PROFIL_PARENT:
guardian = Guardian.objects.filter(profile_role=role).first()
id_associated_person = guardian.id if guardian else None
else:
teacher = Teacher.objects.filter(profile_role=role).first()
id_associated_person = teacher.id if teacher else None
roles_data.append({
'id_associated_person': id_associated_person,
'role_type': role.role_type,
'establishment': role.establishment.id,
'establishment_name': role.establishment.name,
'is_active': role.is_active,
})
return roles_data
def create(self, validated_data):
user = Profile(
@ -107,6 +124,7 @@ class ProfileRoleSerializer(serializers.ModelSerializer):
"registration_status": registration_status
})
return {
"id": guardian.id,
"guardian_name": f"{guardian.last_name} {guardian.first_name}",
"students": students_list
}
@ -118,6 +136,7 @@ class ProfileRoleSerializer(serializers.ModelSerializer):
specialities = teacher.specialities.all()
specialities_list = [{"name": speciality.name, "color_code": speciality.color_code} for speciality in specialities]
return {
"id": teacher.id,
"teacher_name": f"{teacher.last_name} {teacher.first_name}",
"classes": classes_list,
"specialities": specialities_list