mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Ajout de la photo pour le dossier de l'élève + correction
sauvegarde des datas des responsables
This commit is contained in:
@ -48,6 +48,9 @@ class Sibling(models.Model):
|
||||
def __str__(self):
|
||||
return "SIBLING"
|
||||
|
||||
def registration_photo_upload_to(instance, filename):
|
||||
return f"registration_files/dossier_rf_{instance.pk}/parent/{filename}"
|
||||
|
||||
class Student(models.Model):
|
||||
"""
|
||||
Représente l’élève inscrit ou en cours d’inscription.
|
||||
@ -64,6 +67,11 @@ class Student(models.Model):
|
||||
MS = 3, _('MS - Moyenne Section')
|
||||
GS = 4, _('GS - Grande Section')
|
||||
|
||||
photo = models.FileField(
|
||||
upload_to=registration_photo_upload_to,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
last_name = models.CharField(max_length=200, default="")
|
||||
first_name = models.CharField(max_length=200, default="")
|
||||
gender = models.IntegerField(choices=StudentGender, default=StudentGender.NONE, blank=True)
|
||||
@ -239,12 +247,6 @@ class RegistrationForm(models.Model):
|
||||
# Appeler la méthode save originale
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def registration_school_file_upload_to(instance, filename):
|
||||
return f"registration_files/dossier_rf_{instance.registration_form.pk}/school/{filename}"
|
||||
|
||||
def registration_parent_file_upload_to(instance, filename):
|
||||
return f"registration_files/dossier_rf_{instance.registration_form.pk}/parent/{filename}"
|
||||
|
||||
#############################################################
|
||||
####################### MASTER FILES ########################
|
||||
#############################################################
|
||||
@ -269,6 +271,12 @@ class RegistrationParentFileMaster(models.Model):
|
||||
####################### CLONE FILES ########################
|
||||
############################################################
|
||||
|
||||
def registration_school_file_upload_to(instance, filename):
|
||||
return f"registration_files/dossier_rf_{instance.registration_form.pk}/school/{filename}"
|
||||
|
||||
def registration_parent_file_upload_to(instance, filename):
|
||||
return f"registration_files/dossier_rf_{instance.registration_form.pk}/parent/{filename}"
|
||||
|
||||
####### DocuSeal templates (par dossier d'inscription) #######
|
||||
class RegistrationSchoolFileTemplate(models.Model):
|
||||
master = models.ForeignKey(RegistrationSchoolFileMaster, on_delete=models.CASCADE, related_name='school_file_templates', blank=True)
|
||||
|
||||
@ -91,7 +91,25 @@
|
||||
{% load myTemplateTag %}
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1 class="title">{{ pdf_title }}</h1>
|
||||
<div style="position: relative;">
|
||||
<h1 class="title">{{ pdf_title }}</h1>
|
||||
{% if student.photo %}
|
||||
<img
|
||||
src="{{ student.photo }}"
|
||||
alt="Photo de l'élève"
|
||||
style="
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
object-fit: cover;
|
||||
border: 2px solid #333;
|
||||
border-radius: 10px;
|
||||
"
|
||||
/>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
|
||||
@ -229,25 +229,37 @@ class RegisterFormWithIdView(APIView):
|
||||
"""
|
||||
Modifie un dossier d'inscription donné.
|
||||
"""
|
||||
# Récupérer les données de la requête
|
||||
studentForm_data = request.data.copy()
|
||||
|
||||
logger.info(f"Mise à jour du dossier d'inscription {studentForm_data}")
|
||||
studentForm_data = request.data.get('data', '{}')
|
||||
try:
|
||||
data = json.loads(studentForm_data)
|
||||
except json.JSONDecodeError:
|
||||
return JsonResponse({"error": "Invalid JSON format in 'data'"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
_status = studentForm_data.pop('status', 0)
|
||||
if isinstance(_status, list): # Cas Multipart/data, les données sont envoyées sous forme de liste, c'est nul
|
||||
_status = int(_status[0])
|
||||
else:
|
||||
_status = int(_status)
|
||||
# Extraire le fichier photo
|
||||
photo_file = request.FILES.get('photo')
|
||||
|
||||
# Ajouter la photo aux données de l'étudiant
|
||||
if photo_file:
|
||||
data['student']['photo'] = photo_file
|
||||
|
||||
# Gérer le champ `_status`
|
||||
_status = data.pop('status', 0)
|
||||
_status = int(_status)
|
||||
|
||||
# Récupérer le dossier d'inscription
|
||||
registerForm = bdd.getObject(_objectName=RegistrationForm, _columnName='student__id', _value=id)
|
||||
if not registerForm:
|
||||
return JsonResponse({"error": "Dossier d'inscription introuvable"}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
studentForm_serializer = RegistrationFormSerializer(registerForm, data=studentForm_data, partial=True)
|
||||
studentForm_serializer = RegistrationFormSerializer(registerForm, data=data, partial=True)
|
||||
if studentForm_serializer.is_valid():
|
||||
studentForm_serializer.save()
|
||||
|
||||
# Sauvegarder la photo si elle est présente dans la requête
|
||||
if photo_file:
|
||||
student = registerForm.student
|
||||
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