From 2c9aacc3304cbe1161a6e73d64819cbc13aaa59c Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 31 Aug 2021 23:31:36 +0200 Subject: [PATCH] Reorganized fakeportal files --- app/scodoc/pe_view.py | 2 +- tools/demo/__init__.py | 1 - tools/{demo => fakeportal}/demo_reset_noms.py | 2 +- tools/fakeportal/etud_template.xml | 6 +++--- tools/fakeportal/fakeportal.py | 19 +++++++++++-------- tools/{demo => fakeportal}/gen_nomprenoms.py | 14 ++++++++++---- .../{demo => fakeportal/nomsprenoms}/noms.txt | 0 .../nomsprenoms}/prenoms-f.txt | 0 .../nomsprenoms}/prenoms-h.txt | 0 .../nomsprenoms}/prenoms-x.txt | 0 .../nomsprenoms}/prenoms.txt | 0 11 files changed, 26 insertions(+), 18 deletions(-) delete mode 100644 tools/demo/__init__.py rename tools/{demo => fakeportal}/demo_reset_noms.py (98%) rename tools/{demo => fakeportal}/gen_nomprenoms.py (62%) rename tools/{demo => fakeportal/nomsprenoms}/noms.txt (100%) rename tools/{demo => fakeportal/nomsprenoms}/prenoms-f.txt (100%) rename tools/{demo => fakeportal/nomsprenoms}/prenoms-h.txt (100%) rename tools/{demo => fakeportal/nomsprenoms}/prenoms-x.txt (100%) rename tools/{demo => fakeportal/nomsprenoms}/prenoms.txt (100%) diff --git a/app/scodoc/pe_view.py b/app/scodoc/pe_view.py index a8f7007c..45c97acd 100644 --- a/app/scodoc/pe_view.py +++ b/app/scodoc/pe_view.py @@ -170,6 +170,6 @@ def pe_view_sem_recap( return send_file( data, mimetype="application/zip", - download_name=jury.NOM_EXPORT_ZIP + ".zip", + download_name=scu.sanitize_filename(jury.NOM_EXPORT_ZIP + ".zip"), as_attachment=True, ) diff --git a/tools/demo/__init__.py b/tools/demo/__init__.py deleted file mode 100644 index 00d9381d..00000000 --- a/tools/demo/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# Demo package diff --git a/tools/demo/demo_reset_noms.py b/tools/fakeportal/demo_reset_noms.py similarity index 98% rename from tools/demo/demo_reset_noms.py rename to tools/fakeportal/demo_reset_noms.py index 8211f5bb..d1f00cf3 100755 --- a/tools/demo/demo_reset_noms.py +++ b/tools/fakeportal/demo_reset_noms.py @@ -15,7 +15,7 @@ import sys import random import psycopg2 -from .gen_nomprenoms import nomprenom +from gen_nomprenoms import nomprenom def usage(): diff --git a/tools/fakeportal/etud_template.xml b/tools/fakeportal/etud_template.xml index 046b77a1..6b2f2051 100644 --- a/tools/fakeportal/etud_template.xml +++ b/tools/fakeportal/etud_template.xml @@ -22,9 +22,9 @@ N true - MEAUX - 099 - Etranger + {ville_naissance} + {code_dep_naissance} + {libelle_dep_naissance} 01 1 N diff --git a/tools/fakeportal/fakeportal.py b/tools/fakeportal/fakeportal.py index ad119c07..7db85a73 100755 --- a/tools/fakeportal/fakeportal.py +++ b/tools/fakeportal/fakeportal.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 """Simple fake HTTP serveur emulating "Apogee" Web service @@ -13,12 +13,14 @@ import socketserver import sys import time -from tools.demo.gen_nomprenoms import nomprenom +from gen_nomprenoms import nomprenom + +cur_dir = Path(os.path.abspath(__file__)).parent # Etudiant avec tous les champs (USPN) -ETUD_TEMPLATE_FULL = open("etud_template.xml").read() +ETUD_TEMPLATE_FULL = open(cur_dir / "etud_template.xml").read() # Etudiant avec seulement les champs requis -ETUD_TEMPLATE_MINI = open("etud_minimal_template.xml").read() +ETUD_TEMPLATE_MINI = open(cur_dir / "etud_minimal_template.xml").read() ETUD_HEAD = """ """ @@ -44,6 +46,10 @@ def make_random_etud(nip, etape=None, annee=None, template=ETUD_TEMPLATE_FULL): etape=etape, diplome=diplome, annee=annee, + ville_naissance=random.choice(("Paris", "Berlin", "Londres", "")), + code_dep_naissance=random.choice(("75", "99", "89")), + libelle_dep_naissance="nom département", + # nomlycee= ) return data @@ -130,11 +136,8 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): return -# Create an object of the above class -handler_object = MyHttpRequestHandler - PORT = 8678 -my_server = socketserver.TCPServer(("", PORT), handler_object) +my_server = socketserver.TCPServer(("", PORT), MyHttpRequestHandler) if __name__ == "__main__": # Start the server diff --git a/tools/demo/gen_nomprenoms.py b/tools/fakeportal/gen_nomprenoms.py similarity index 62% rename from tools/demo/gen_nomprenoms.py rename to tools/fakeportal/gen_nomprenoms.py index 6ab85188..bf4d412a 100644 --- a/tools/demo/gen_nomprenoms.py +++ b/tools/fakeportal/gen_nomprenoms.py @@ -7,10 +7,16 @@ from pathlib import Path cur_dir = Path(os.path.abspath(__file__)).parent # Noms et prénoms les plus fréquents en France: -NOMS = [x.strip() for x in open(cur_dir / "noms.txt").readlines()] -PRENOMS_H = [x.strip() for x in open(cur_dir / "prenoms-h.txt").readlines()] -PRENOMS_F = [x.strip() for x in open(cur_dir / "prenoms-f.txt").readlines()] -PRENOMS_X = [x.strip() for x in open(cur_dir / "prenoms-x.txt").readlines()] +NOMS = [x.strip() for x in open(cur_dir / "nomsprenoms" / "noms.txt").readlines()] +PRENOMS_H = [ + x.strip() for x in open(cur_dir / "nomsprenoms" / "prenoms-h.txt").readlines() +] +PRENOMS_F = [ + x.strip() for x in open(cur_dir / "nomsprenoms" / "prenoms-f.txt").readlines() +] +PRENOMS_X = [ + x.strip() for x in open(cur_dir / "nomsprenoms" / "prenoms-x.txt").readlines() +] def nomprenom(civilite): diff --git a/tools/demo/noms.txt b/tools/fakeportal/nomsprenoms/noms.txt similarity index 100% rename from tools/demo/noms.txt rename to tools/fakeportal/nomsprenoms/noms.txt diff --git a/tools/demo/prenoms-f.txt b/tools/fakeportal/nomsprenoms/prenoms-f.txt similarity index 100% rename from tools/demo/prenoms-f.txt rename to tools/fakeportal/nomsprenoms/prenoms-f.txt diff --git a/tools/demo/prenoms-h.txt b/tools/fakeportal/nomsprenoms/prenoms-h.txt similarity index 100% rename from tools/demo/prenoms-h.txt rename to tools/fakeportal/nomsprenoms/prenoms-h.txt diff --git a/tools/demo/prenoms-x.txt b/tools/fakeportal/nomsprenoms/prenoms-x.txt similarity index 100% rename from tools/demo/prenoms-x.txt rename to tools/fakeportal/nomsprenoms/prenoms-x.txt diff --git a/tools/demo/prenoms.txt b/tools/fakeportal/nomsprenoms/prenoms.txt similarity index 100% rename from tools/demo/prenoms.txt rename to tools/fakeportal/nomsprenoms/prenoms.txt