mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
fix: Ne pas dissocier de responsable s'il n'y en a pas d'autre rattaché
à l'élève
This commit is contained in:
@ -50,11 +50,22 @@ class DissociateGuardianView(APIView):
|
||||
# Récupérer le guardian
|
||||
guardian = Guardian.objects.get(id=guardian_id)
|
||||
|
||||
# Vérifier s'il y a d'autres guardians associés au student
|
||||
other_guardians = student.guardians.exclude(id=guardian_id)
|
||||
if not other_guardians.exists():
|
||||
return JsonResponse(
|
||||
{"error": "Impossible de dissocier ce responsable car il n'en existe aucun autre rattaché à l'élève."},
|
||||
status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
# Supprimer la relation entre le student et le guardian
|
||||
student.guardians.remove(guardian)
|
||||
|
||||
if guardian.profile_role:
|
||||
guardian.profile_role.save()
|
||||
# Mettre à jour le responsable principal (par exemple, le premier autre guardian)
|
||||
new_main_guardian = other_guardians.first()
|
||||
if new_main_guardian:
|
||||
# Logique pour définir le nouveau responsable principal
|
||||
print(f"Le guardian {new_main_guardian} devient le responsable principal.")
|
||||
|
||||
isGuardianDeleted = False
|
||||
# Vérifier si le guardian n'est plus associé à aucun élève
|
||||
@ -76,16 +87,6 @@ class DissociateGuardianView(APIView):
|
||||
# Supprimer le guardian
|
||||
guardian.delete()
|
||||
|
||||
# Récupérer le RegistrationForm associé au Student
|
||||
registerForm = bdd.getObject(RegistrationForm, "student__id", student_id)
|
||||
if registerForm:
|
||||
# Réinitialiser le statut en "Créé"
|
||||
registerForm.status = RegistrationForm.RegistrationFormStatus.RF_CREATED
|
||||
registerForm.save()
|
||||
|
||||
# Supprimer le fichier et le dossier associés
|
||||
util.delete_registration_files(registerForm)
|
||||
|
||||
return JsonResponse(
|
||||
{
|
||||
"message": f"Le guardian {guardian.last_name} {guardian.first_name} a été dissocié de l'étudiant {student.last_name} {student.first_name}.",
|
||||
|
||||
Reference in New Issue
Block a user