mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Ajout de la fratrie [#27]
This commit is contained in:
@ -266,6 +266,23 @@ class RegisterFormWithIdView(APIView):
|
||||
# Sauvegarder la photo si elle est présente dans la requête
|
||||
if photo_file:
|
||||
student = registerForm.student
|
||||
|
||||
# Vérifier si une photo existante est déjà associée à l'étudiant
|
||||
if student.photo and student.photo.name:
|
||||
# Construire le chemin complet du fichier existant
|
||||
if os.path.isabs(student.photo.name):
|
||||
existing_file_path = student.photo.name
|
||||
else:
|
||||
existing_file_path = os.path.join(settings.MEDIA_ROOT, student.photo.name.lstrip('/'))
|
||||
|
||||
# Vérifier si le fichier existe et le supprimer
|
||||
if os.path.exists(existing_file_path):
|
||||
os.remove(existing_file_path)
|
||||
student.photo.delete(save=False)
|
||||
else:
|
||||
print(f'File does not exist: {existing_file_path}')
|
||||
|
||||
# Sauvegarder la nouvelle photo
|
||||
student.photo.save(photo_file.name, photo_file, save=True)
|
||||
else:
|
||||
return JsonResponse(studentForm_serializer.errors, safe=False, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
Reference in New Issue
Block a user