fix: Récupération d'un template donné

This commit is contained in:
N3WT DE COMPET
2025-03-01 16:05:16 +01:00
parent 085c086ec7
commit 9b13d52e8d
5 changed files with 8 additions and 65 deletions

View File

@ -6,7 +6,9 @@ from Subscriptions.models import (
Guardian, Guardian,
Fee, Fee,
Discount, Discount,
RegistrationFileGroup RegistrationFileGroup,
RegistrationTemplateMaster,
RegistrationTemplate
) )
from Auth.models import Profile from Auth.models import Profile
from School.models import ( from School.models import (
@ -43,7 +45,6 @@ class Command(BaseCommand):
self.create_or_update_teachers() self.create_or_update_teachers()
self.create_or_update_school_classes() self.create_or_update_school_classes()
self.create_or_update_registration_file_group() self.create_or_update_registration_file_group()
# self.create_or_update_registration_file_template()
self.create_register_form() self.create_register_form()
def create_or_update_establishment(self): 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.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')) 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): def create_register_form(self):
fake = Faker('fr_FR') # Utiliser le locale français pour Faker fake = Faker('fr_FR') # Utiliser le locale français pour Faker

View File

@ -29,7 +29,7 @@ urlpatterns = [
re_path(r'^lastGuardianId$', GuardianView.as_view(), name="lastGuardianId"), re_path(r'^lastGuardianId$', GuardianView.as_view(), name="lastGuardianId"),
re_path(r'^registrationFileGroups/(?P<id>[0-9]+)$', RegistrationFileGroupSimpleView.as_view(), name='registrationFileGroupDetail'), re_path(r'^registrationFileGroups/(?P<id>[0-9]+)$', RegistrationFileGroupSimpleView.as_view(), name='registrationFileGroupDetail'),
re_path(r'^registrationFileGroups/(?P<id>[0-9]+)/registrationFiles$', get_registration_files_by_group, name="get_registration_files_by_group"), re_path(r'^registrationFileGroups/(?P<id>[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'^registrationFileGroups$', RegistrationFileGroupView.as_view(), name='registrationFileGroups'),
re_path(r'^registrationTemplateMasters/(?P<id>[0-9]+)$', RegistrationTemplateMasterSimpleView.as_view(), name='registrationTemplateMasters'), re_path(r'^registrationTemplateMasters/(?P<id>[0-9]+)$', RegistrationTemplateMasterSimpleView.as_view(), name='registrationTemplateMasters'),

View File

@ -118,7 +118,7 @@ class RegistrationFileGroupSimpleView(APIView):
def get_registration_files_by_group(request, id): def get_registration_files_by_group(request, id):
try: try:
group = RegistrationFileGroup.objects.get(id=id) group = RegistrationFileGroup.objects.get(id=id)
templates = RegistrationTemplateMaster.objects.filter(group=group) templates = RegistrationTemplateMaster.objects.filter(groups=group)
templates_data = list(templates.values()) templates_data = list(templates.values())
return JsonResponse(templates_data, safe=False) return JsonResponse(templates_data, safe=False)
except RegistrationFileGroup.DoesNotExist: except RegistrationFileGroup.DoesNotExist:

View File

@ -76,7 +76,7 @@ export const editRegistrationFileGroup = async (groupId, groupData, csrfToken) =
}; };
export const fetchRegistrationFileFromGroup = async (groupId) => { 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', credentials: 'include',
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',

View File

@ -307,7 +307,7 @@ export default function FilesGroupsManagement({ csrfToken }) {
/> />
<div className="mt-8 mb-4"> <div className="mt-8 mb-4">
<div className="flex justify-between items-center mb-4"> <div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-bold">Groupes de templateMasters</h2> <h2 className="text-xl font-bold">Groupes de fichiers</h2>
<button <button
onClick={() => setIsGroupModalOpen(true)} onClick={() => setIsGroupModalOpen(true)}
className="flex items-center bg-blue-600 text-white p-2 rounded-full shadow hover:bg-blue-900 transition duration-200" className="flex items-center bg-blue-600 text-white p-2 rounded-full shadow hover:bg-blue-900 transition duration-200"
@ -326,7 +326,7 @@ export default function FilesGroupsManagement({ csrfToken }) {
{groups.length > 0 && ( {groups.length > 0 && (
<div className="mt-8"> <div className="mt-8">
<div className="flex justify-between items-center mb-4"> <div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-bold">templateMasters</h2> <h2 className="text-xl font-bold">Fichiers</h2>
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
<select <select
className="border rounded p-2" className="border rounded p-2"