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,
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