feat: Ajout de la fratrie [#27]

This commit is contained in:
N3WT DE COMPET
2025-05-02 17:44:35 +02:00
parent 1ced4a1069
commit 4a382d523c
8 changed files with 279 additions and 30 deletions

View File

@ -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)