fix: Edition d'un teacher, champ email désactivé [N3WTS-1]

This commit is contained in:
N3WT DE COMPET
2026-02-15 15:47:51 +01:00
parent 92c6a31740
commit 176edc5c45
3 changed files with 105 additions and 113 deletions

View File

@ -118,11 +118,23 @@ class TeacherDetailView(APIView):
return JsonResponse(teacher_serializer.data, safe=False)
def put(self, request, id):
teacher_data=JSONParser().parse(request)
teacher_data = JSONParser().parse(request)
teacher = getObject(_objectName=Teacher, _columnName='id', _value=id)
# Récupérer l'ancien profile avant modification
old_profile_role = getattr(teacher, 'profile_role', None)
old_profile = getattr(old_profile_role, 'profile', None) if old_profile_role else None
teacher_serializer = TeacherSerializer(teacher, data=teacher_data)
if teacher_serializer.is_valid():
teacher_serializer.save()
# Après modification, vérifier si l'ancien profile n'a plus de ProfileRole
if old_profile:
from Auth.models import ProfileRole # import local pour éviter les imports circulaires
if not ProfileRole.objects.filter(profile=old_profile).exists():
old_profile.delete()
return JsonResponse(teacher_serializer.data, safe=False)
return JsonResponse(teacher_serializer.errors, safe=False)