From 912a213dcdee3c3af0e0961d3b5e36380d63f7b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 1 Jun 2024 14:28:42 +0200 Subject: [PATCH] Rafraichissement image lors changement photo etud. Pres. trombi. Photos pour demos. --- app/scodoc/sco_photos.py | 21 +++++++++++++++++---- app/static/css/scodoc.css | 33 ++++++++++++++++++++++++++------- sco_version.py | 2 +- tools/fakeportal/fakeportal.py | 33 +++++++++++++++++++++++++++------ 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index 5c4bfbdc..35b2ea12 100755 --- a/app/scodoc/sco_photos.py +++ b/app/scodoc/sco_photos.py @@ -96,13 +96,16 @@ def photo_portal_url(code_nip: str): return None -def get_etud_photo_url(etudid, size="small"): +def get_etud_photo_url(etudid, size="small", seed=None): + "L'URL scodoc vers la photo de l'étudiant" + kwargs = {"seed": seed} if seed else {} return ( url_for( "scolar.get_photo_image", scodoc_dept=g.scodoc_dept, etudid=etudid, size=size, + **kwargs, ) if has_request_context() else "" @@ -114,9 +117,11 @@ def etud_photo_url(etud: dict, size="small", fast=False) -> str: If ScoDoc doesn't have an image and a portal is configured, link to it. """ - photo_url = get_etud_photo_url(etud["etudid"], size=size) if fast: - return photo_url + return get_etud_photo_url(etud["etudid"], size=size) + photo_url = get_etud_photo_url( + etud["etudid"], size=size, seed=hash(etud.get("photo_filename")) + ) path = photo_pathname(etud["photo_filename"], size=size) if not path: # Portail ? @@ -374,7 +379,15 @@ def copy_portal_photo_to_fs(etudid: int): portal_timeout = sco_preferences.get_preference("portal_timeout") error_message = None try: - r = requests.get(url, timeout=portal_timeout) + r = requests.get( + url, + timeout=portal_timeout, + params={ + "nom": etud.nom or "", + "prenom": etud.prenom or "", + "civilite": etud.civilite, + }, + ) except requests.ConnectionError: error_message = "ConnectionError" except requests.Timeout: diff --git a/app/static/css/scodoc.css b/app/static/css/scodoc.css index 0f152235..c4d55976 100644 --- a/app/static/css/scodoc.css +++ b/app/static/css/scodoc.css @@ -1085,18 +1085,35 @@ span.spanlink:hover { } .trombi_box { - display: inline-block; - width: 110px; - vertical-align: top; margin-left: 5px; margin-top: 5px; + width: 140px; + /* Constant width for the box */ + display: inline-flex; + flex-direction: column; + /* Ensures trombi-photo is above trombi_legend */ + align-items: center; + /* Centers content horizontally */ } -span.trombi_legend { - display: inline-block; +.trombi-photo { + display: flex; + justify-content: center; + /* Centers image horizontally within the photo container */ + margin-bottom: 10px; + /* Adds some space between the photo and the legend */ } -span.trombi-photo { +.trombi-photo img { + width: auto; + /* Maintains aspect ratio */ + height: 120px; + /* Sets the height to 90px */ + max-width: 100%; + /* Ensures the image doesn't exceed the container's width */ +} + +/* span.trombi_legend { display: inline-block; } @@ -1106,7 +1123,9 @@ span.trombi_box a { span.trombi_box a img { display: inline-block; -} + height: 128px; + width: auto; +} */ .trombi_nom { display: block; diff --git a/sco_version.py b/sco_version.py index ffcc3e8a..71a0b594 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.969" +SCOVERSION = "9.6.970" SCONAME = "ScoDoc" diff --git a/tools/fakeportal/fakeportal.py b/tools/fakeportal/fakeportal.py index 785f5856..7e9abe7e 100755 --- a/tools/fakeportal/fakeportal.py +++ b/tools/fakeportal/fakeportal.py @@ -28,7 +28,20 @@ script_dir = Path(os.path.abspath(__file__)).parent os.chdir(script_dir) # Les "photos" des étudiants -FAKE_FACES_PATHS = list((Path("faces").glob("*.jpg"))) +if os.path.exists("/opt/ExtraFaces"): + FAKE_FACES_PATHS = list((Path("extra_faces").glob("*/*.jpg"))) + FAKE_FACES_PATHS_BY_CIVILITE = { + "M": list((Path("extra_faces").glob("M/*.jpg"))), + "F": list((Path("extra_faces").glob("F/*.jpg"))), + "X": list((Path("extra_faces").glob("X/*.jpg"))), + } +else: + FAKE_FACES_PATHS = list((Path("faces").glob("*.jpg"))) + FAKE_FACES_PATHS_BY_CIVILITE = { + "M": FAKE_FACES_PATHS, + "F": FAKE_FACES_PATHS, + "X": FAKE_FACES_PATHS, + } # Etudiant avec tous les champs (USPN) ETUD_TEMPLATE_FULL = open(script_dir / "etud_template.xml").read() @@ -84,16 +97,22 @@ def make_random_etape_etuds(etape, annee): return "\n".join(L) -def get_photo_filename(nip: str) -> str: +def get_photo_filename(nip: str, civilite: str | None = None) -> str: """get an existing filename for a fake photo, found in faces/ Returns a path relative to the current working dir + If civilite is not None, use it to select a subdir """ - # - nb_faces = len(FAKE_FACES_PATHS) + print("get_photo_filename") + if civilite: + faces = FAKE_FACES_PATHS_BY_CIVILITE[civilite] + else: + faces = FAKE_FACES_PATHS + nb_faces = len(faces) if nb_faces == 0: print("WARNING: aucun fichier image disponible !") return "" - return FAKE_FACES_PATHS[hash(nip) % nb_faces] + print(faces[hash(nip) % nb_faces]) + return faces[hash(nip) % nb_faces] class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): @@ -139,7 +158,9 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): return elif ("getPhoto" in self.path) or ("scodocPhoto" in self.path): nip = query_components["nip"][0] - self.path = str(get_photo_filename(nip)) + civilite = query_components.get("civilite") + civilite = civilite[0] if civilite else None + self.path = str(get_photo_filename(nip, civilite=civilite)) print(f"photo for nip={nip}: {self.path}") else: print(f"Error 404: path={self.path}")