From 9b13d52e8d8926bcc6f756ff4d2c9d278a0cc387 Mon Sep 17 00:00:00 2001 From: N3WT DE COMPET Date: Sat, 1 Mar 2025 16:05:16 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20R=C3=A9cup=C3=A9ration=20d'un=20template?= =?UTF-8?q?=20donn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/init_mock_datas.py | 63 +------------------ Back-End/Subscriptions/urls.py | 2 +- .../views/registration_file_group_views.py | 2 +- .../app/actions/registerFileGroupAction.js | 2 +- .../Structure/Files/FilesGroupsManagement.js | 4 +- 5 files changed, 8 insertions(+), 65 deletions(-) diff --git a/Back-End/School/management/commands/init_mock_datas.py b/Back-End/School/management/commands/init_mock_datas.py index 4ae7ed3..5b12a09 100644 --- a/Back-End/School/management/commands/init_mock_datas.py +++ b/Back-End/School/management/commands/init_mock_datas.py @@ -6,7 +6,9 @@ from Subscriptions.models import ( Guardian, Fee, Discount, - RegistrationFileGroup + RegistrationFileGroup, + RegistrationTemplateMaster, + RegistrationTemplate ) from Auth.models import Profile from School.models import ( @@ -43,7 +45,6 @@ class Command(BaseCommand): self.create_or_update_teachers() self.create_or_update_school_classes() self.create_or_update_registration_file_group() - # self.create_or_update_registration_file_template() self.create_register_form() def create_or_update_establishment(self): @@ -392,64 +393,6 @@ class Command(BaseCommand): self.registration_file_group_2, created = RegistrationFileGroup.objects.get_or_create(name=group_data_2["name"], defaults=group_data_2) self.stdout.write(self.style.SUCCESS('RegistrationFileGroup 2 initialized or updated successfully')) - def create_or_update_registration_file_template(self): - script_dir = os.path.dirname(os.path.abspath(__file__)) - references_dir = os.path.join(script_dir, 'References', 'LMDE') - - templates_data = [ - { - "name": "RIB LA MAISON DES ENFANTS", - "file": "RIB LA MAISON DES ENFANTS.pdf", - "order": 0, - "is_required": False, - "group": self.registration_file_group_2 # Associer ce fichier au deuxième groupe - }, - { - "name": "Contrat d'engagement 2024 2025", - "file": "Contrat d'engagement 2024 2025.pdf", - "order": 0, - "is_required": True, - "group": self.registration_file_group_1 - }, - { - "name": "Bulletin d'adhésion familiale scolaire", - "file": "Bulletin d'adhésion familiale scolaire.pdf", - "order": 0, - "is_required": True, - "group": self.registration_file_group_1 - }, - { - "name": "Fiche sanitaire de liaison", - "file": "Fiche sanitaire de liaison.pdf", - "order": 0, - "is_required": True, - "group": self.registration_file_group_1 - } - ] - - for template_data in templates_data: - file_path = os.path.join(references_dir, template_data["file"]) - references_dir_realpath = os.path.realpath(references_dir) - file_path_realpath = os.path.realpath(file_path) - if not file_path_realpath.startswith(references_dir_realpath): - raise SuspiciousFileOperation(f"Detected path traversal attempt in '{file_path_realpath}'") - if not os.path.exists(file_path_realpath): - raise FileNotFoundError(f"File not found: {file_path_realpath}") - with open(file_path_realpath, 'rb') as file: - RegistrationFileTemplate.objects.update_or_create( - name=template_data["name"], - defaults={ - "file": File(file, name=template_data["file"]), - "order": template_data["order"], - "is_required": template_data["is_required"], - "group": template_data["group"] - } - ) - - self.stdout.write(self.style.SUCCESS('RegistrationFileTemplates initialized or updated successfully')) - - from faker import Faker - def create_register_form(self): fake = Faker('fr_FR') # Utiliser le locale français pour Faker diff --git a/Back-End/Subscriptions/urls.py b/Back-End/Subscriptions/urls.py index beba111..41dc824 100644 --- a/Back-End/Subscriptions/urls.py +++ b/Back-End/Subscriptions/urls.py @@ -29,7 +29,7 @@ urlpatterns = [ re_path(r'^lastGuardianId$', GuardianView.as_view(), name="lastGuardianId"), re_path(r'^registrationFileGroups/(?P[0-9]+)$', RegistrationFileGroupSimpleView.as_view(), name='registrationFileGroupDetail'), - re_path(r'^registrationFileGroups/(?P[0-9]+)/registrationFiles$', get_registration_files_by_group, name="get_registration_files_by_group"), + re_path(r'^registrationFileGroups/(?P[0-9]+)/templates$', get_registration_files_by_group, name="get_registration_files_by_group"), re_path(r'^registrationFileGroups$', RegistrationFileGroupView.as_view(), name='registrationFileGroups'), re_path(r'^registrationTemplateMasters/(?P[0-9]+)$', RegistrationTemplateMasterSimpleView.as_view(), name='registrationTemplateMasters'), diff --git a/Back-End/Subscriptions/views/registration_file_group_views.py b/Back-End/Subscriptions/views/registration_file_group_views.py index 21da8c4..a74af89 100644 --- a/Back-End/Subscriptions/views/registration_file_group_views.py +++ b/Back-End/Subscriptions/views/registration_file_group_views.py @@ -118,7 +118,7 @@ class RegistrationFileGroupSimpleView(APIView): def get_registration_files_by_group(request, id): try: group = RegistrationFileGroup.objects.get(id=id) - templates = RegistrationTemplateMaster.objects.filter(group=group) + templates = RegistrationTemplateMaster.objects.filter(groups=group) templates_data = list(templates.values()) return JsonResponse(templates_data, safe=False) except RegistrationFileGroup.DoesNotExist: diff --git a/Front-End/src/app/actions/registerFileGroupAction.js b/Front-End/src/app/actions/registerFileGroupAction.js index 0341474..5a2a056 100644 --- a/Front-End/src/app/actions/registerFileGroupAction.js +++ b/Front-End/src/app/actions/registerFileGroupAction.js @@ -76,7 +76,7 @@ export const editRegistrationFileGroup = async (groupId, groupData, csrfToken) = }; export const fetchRegistrationFileFromGroup = async (groupId) => { - const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}/registrationFiles`, { + const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}/templates`, { credentials: 'include', headers: { 'Accept': 'application/json', diff --git a/Front-End/src/components/Structure/Files/FilesGroupsManagement.js b/Front-End/src/components/Structure/Files/FilesGroupsManagement.js index 1763176..10ccf74 100644 --- a/Front-End/src/components/Structure/Files/FilesGroupsManagement.js +++ b/Front-End/src/components/Structure/Files/FilesGroupsManagement.js @@ -307,7 +307,7 @@ export default function FilesGroupsManagement({ csrfToken }) { />
-

Groupes de templateMasters

+

Groupes de fichiers