mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
fix: Récupération d'un template donné
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ urlpatterns = [
|
||||
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]+)/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'^registrationTemplateMasters/(?P<id>[0-9]+)$', RegistrationTemplateMasterSimpleView.as_view(), name='registrationTemplateMasters'),
|
||||
|
||||
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user