feat: Formulaire de création RF sur une seule pag

This commit is contained in:
N3WT DE COMPET
2025-05-05 20:57:51 +02:00
parent 2a6b3bdf63
commit 76f9a7dd14
19 changed files with 1299 additions and 422 deletions

View File

@ -25,8 +25,8 @@ class Guardian(models.Model):
"""
Représente un responsable légal (parent/tuteur) dun élève.
"""
last_name = models.CharField(max_length=200, default="")
first_name = models.CharField(max_length=200, default="")
last_name = models.CharField(max_length=200, null=True, blank=True)
first_name = models.CharField(max_length=200, null=True, blank=True)
birth_date = models.DateField(null=True, blank=True)
address = models.CharField(max_length=200, default="", blank=True)
phone = models.CharField(max_length=200, default="", blank=True)
@ -49,8 +49,8 @@ class Sibling(models.Model):
"""
Représente un frère ou une sœur dun élève.
"""
last_name = models.CharField(max_length=200, default="")
first_name = models.CharField(max_length=200, default="")
last_name = models.CharField(max_length=200, null=True, blank=True)
first_name = models.CharField(max_length=200, null=True, blank=True)
birth_date = models.DateField(null=True, blank=True)
def __str__(self):
@ -218,6 +218,7 @@ class RegistrationForm(models.Model):
student = models.OneToOneField(Student, on_delete=models.CASCADE, primary_key=True)
status = models.IntegerField(choices=RegistrationFormStatus, default=RegistrationFormStatus.RF_IDLE)
last_update = models.DateTimeField(auto_now=True)
school_year = models.CharField(max_length=9, default="", blank=True)
notes = models.CharField(max_length=200, blank=True)
registration_link_code = models.CharField(max_length=200, default="", blank=True)
registration_file = models.FileField(

View File

@ -343,7 +343,7 @@ class GuardianByDICreationSerializer(serializers.ModelSerializer):
class Meta:
model = Guardian
fields = ['id', 'last_name', 'first_name', 'associated_profile_email']
fields = ['id', 'last_name', 'first_name', 'associated_profile_email', 'phone']
def get_associated_profile_email(self, obj):
if obj.profile_role and obj.profile_role.profile:
@ -356,7 +356,7 @@ class StudentByRFCreationSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ['id', 'last_name', 'first_name', 'guardians']
fields = ['id', 'last_name', 'first_name', 'guardians', 'level']
def __init__(self, *args, **kwargs):
super(StudentByRFCreationSerializer, self).__init__(*args, **kwargs)

View File

@ -174,4 +174,45 @@ def delete_registration_files(registerForm):
registerForm.registration_file.delete(save=False)
if os.path.exists(base_dir):
shutil.rmtree(base_dir)
shutil.rmtree(base_dir)
from datetime import datetime
def getCurrentSchoolYear():
"""
Retourne l'année scolaire en cours au format "YYYY-YYYY".
Exemple : Si nous sommes en octobre 2023, retourne "2023-2024".
"""
now = datetime.now()
current_year = now.year
current_month = now.month
# Si nous sommes avant septembre, l'année scolaire a commencé l'année précédente
start_year = current_year if current_month >= 9 else current_year - 1
return f"{start_year}-{start_year + 1}"
def getNextSchoolYear():
"""
Retourne l'année scolaire suivante au format "YYYY-YYYY".
Exemple : Si nous sommes en octobre 2023, retourne "2024-2025".
"""
current_school_year = getCurrentSchoolYear()
start_year, end_year = map(int, current_school_year.split('-'))
return f"{start_year + 1}-{end_year + 1}"
def getHistoricalYears(count=5):
"""
Retourne un tableau des années scolaires passées au format "YYYY-YYYY".
Exemple : ["2022-2023", "2021-2022", "2020-2021"].
:param count: Le nombre d'années scolaires passées à inclure.
"""
current_school_year = getCurrentSchoolYear()
start_year = int(current_school_year.split('-')[0])
historical_years = []
for i in range(1, count + 1):
historical_start_year = start_year - i
historical_years.append(f"{historical_start_year}-{historical_start_year + 1}")
return historical_years

View File

@ -33,7 +33,7 @@ class RegisterFormView(APIView):
@swagger_auto_schema(
manual_parameters=[
openapi.Parameter('filter', openapi.IN_QUERY, description="filtre", type=openapi.TYPE_STRING, enum=['pending', 'archived', 'subscribed'], required=True),
openapi.Parameter('filter', openapi.IN_QUERY, description="filtre", type=openapi.TYPE_STRING, enum=['current_year', 'next_year', 'historical'], required=True),
openapi.Parameter('search', openapi.IN_QUERY, description="search", type=openapi.TYPE_STRING, required=False),
openapi.Parameter('page_size', openapi.IN_QUERY, description="limite de page lors de la pagination", type=openapi.TYPE_INTEGER, required=False),
openapi.Parameter('establishment_id', openapi.IN_QUERY, description="ID de l'établissement", type=openapi.TYPE_INTEGER, required=True),
@ -51,7 +51,7 @@ class RegisterFormView(APIView):
"last_name": "Doe",
"date_of_birth": "2010-01-01"
},
"status": "pending",
"status": "current_year",
"last_update": "10-02-2025 10:00"
},
{
@ -62,7 +62,7 @@ class RegisterFormView(APIView):
"last_name": "Doe",
"date_of_birth": "2011-02-02"
},
"status": "archived",
"status": "historical",
"last_update": "09-02-2025 09:00"
}
]
@ -85,14 +85,19 @@ class RegisterFormView(APIView):
except ValueError:
page_size = settings.NB_RESULT_PER_PAGE
# Récupérer les dossier d'inscriptions en fonction du filtre
# Récupérer les années scolaires
current_year = util.getCurrentSchoolYear()
next_year = util.getNextSchoolYear()
historical_years = util.getHistoricalYears()
# Récupérer les dossiers d'inscriptions en fonction du filtre
registerForms_List = None
if filter == 'pending':
exclude_states = [RegistrationForm.RegistrationFormStatus.RF_VALIDATED, RegistrationForm.RegistrationFormStatus.RF_ARCHIVED]
registerForms_List = bdd.searchObjects(RegistrationForm, search, _excludeStates=exclude_states)
elif filter == 'archived':
registerForms_List = bdd.getObjects(RegistrationForm, 'status', RegistrationForm.RegistrationFormStatus.RF_ARCHIVED)
elif filter == 'subscribed':
if filter == 'current_year':
registerForms_List = RegistrationForm.objects.filter(school_year=current_year)
elif filter == 'next_year':
registerForms_List = RegistrationForm.objects.filter(school_year=next_year)
elif filter == 'historical':
registerForms_List = RegistrationForm.objects.filter(school_year__in=historical_years)
registerForms_List = bdd.getObjects(RegistrationForm, 'status', RegistrationForm.RegistrationFormStatus.RF_VALIDATED)
else:
registerForms_List = None
@ -126,7 +131,7 @@ class RegisterFormView(APIView):
"last_name": "Doe",
"date_of_birth": "2010-01-01"
},
"status": "pending",
"status": "current_year",
"last_update": "10-02-2025 10:00",
"codeLienInscription": "ABC123XYZ456"
}
@ -514,4 +519,5 @@ def get_parent_file_templates_by_rf(request, id):
# Retourner les données sérialisées
return JsonResponse(serializer.data, safe=False)
except RegistrationParentFileTemplate.DoesNotExist:
return JsonResponse({'error': 'Aucune pièce à fournir trouvée pour ce dossier d\'inscription'}, status=status.HTTP_404_NOT_FOUND)
return JsonResponse({'error': 'Aucune pièce à fournir trouvée pour ce dossier d\'inscription'}, status=status.HTTP_404_NOT_FOUND)