mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-03 16:51:26 +00:00
fix: Edition d'un teacher, champ email désactivé [N3WTS-1]
This commit is contained in:
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user