forked from ScoDoc/ScoDoc
Rafraichissement image lors changement photo etud. Pres. trombi. Photos pour demos.
This commit is contained in:
parent
3575e89dc0
commit
912a213dcd
@ -96,13 +96,16 @@ def photo_portal_url(code_nip: str):
|
|||||||
return None
|
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 (
|
return (
|
||||||
url_for(
|
url_for(
|
||||||
"scolar.get_photo_image",
|
"scolar.get_photo_image",
|
||||||
scodoc_dept=g.scodoc_dept,
|
scodoc_dept=g.scodoc_dept,
|
||||||
etudid=etudid,
|
etudid=etudid,
|
||||||
size=size,
|
size=size,
|
||||||
|
**kwargs,
|
||||||
)
|
)
|
||||||
if has_request_context()
|
if has_request_context()
|
||||||
else ""
|
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.
|
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:
|
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)
|
path = photo_pathname(etud["photo_filename"], size=size)
|
||||||
if not path:
|
if not path:
|
||||||
# Portail ?
|
# Portail ?
|
||||||
@ -374,7 +379,15 @@ def copy_portal_photo_to_fs(etudid: int):
|
|||||||
portal_timeout = sco_preferences.get_preference("portal_timeout")
|
portal_timeout = sco_preferences.get_preference("portal_timeout")
|
||||||
error_message = None
|
error_message = None
|
||||||
try:
|
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:
|
except requests.ConnectionError:
|
||||||
error_message = "ConnectionError"
|
error_message = "ConnectionError"
|
||||||
except requests.Timeout:
|
except requests.Timeout:
|
||||||
|
@ -1085,18 +1085,35 @@ span.spanlink:hover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.trombi_box {
|
.trombi_box {
|
||||||
display: inline-block;
|
|
||||||
width: 110px;
|
|
||||||
vertical-align: top;
|
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
margin-top: 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 {
|
.trombi-photo {
|
||||||
display: inline-block;
|
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;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1106,7 +1123,9 @@ span.trombi_box a {
|
|||||||
|
|
||||||
span.trombi_box a img {
|
span.trombi_box a img {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
height: 128px;
|
||||||
|
width: auto;
|
||||||
|
} */
|
||||||
|
|
||||||
.trombi_nom {
|
.trombi_nom {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# -*- mode: python -*-
|
# -*- mode: python -*-
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
SCOVERSION = "9.6.969"
|
SCOVERSION = "9.6.970"
|
||||||
|
|
||||||
SCONAME = "ScoDoc"
|
SCONAME = "ScoDoc"
|
||||||
|
|
||||||
|
@ -28,7 +28,20 @@ script_dir = Path(os.path.abspath(__file__)).parent
|
|||||||
os.chdir(script_dir)
|
os.chdir(script_dir)
|
||||||
|
|
||||||
# Les "photos" des étudiants
|
# Les "photos" des étudiants
|
||||||
|
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 = 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)
|
# Etudiant avec tous les champs (USPN)
|
||||||
ETUD_TEMPLATE_FULL = open(script_dir / "etud_template.xml").read()
|
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)
|
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/
|
"""get an existing filename for a fake photo, found in faces/
|
||||||
Returns a path relative to the current working dir
|
Returns a path relative to the current working dir
|
||||||
|
If civilite is not None, use it to select a subdir
|
||||||
"""
|
"""
|
||||||
#
|
print("get_photo_filename")
|
||||||
nb_faces = len(FAKE_FACES_PATHS)
|
if civilite:
|
||||||
|
faces = FAKE_FACES_PATHS_BY_CIVILITE[civilite]
|
||||||
|
else:
|
||||||
|
faces = FAKE_FACES_PATHS
|
||||||
|
nb_faces = len(faces)
|
||||||
if nb_faces == 0:
|
if nb_faces == 0:
|
||||||
print("WARNING: aucun fichier image disponible !")
|
print("WARNING: aucun fichier image disponible !")
|
||||||
return ""
|
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):
|
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
@ -139,7 +158,9 @@ class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
|||||||
return
|
return
|
||||||
elif ("getPhoto" in self.path) or ("scodocPhoto" in self.path):
|
elif ("getPhoto" in self.path) or ("scodocPhoto" in self.path):
|
||||||
nip = query_components["nip"][0]
|
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}")
|
print(f"photo for nip={nip}: {self.path}")
|
||||||
else:
|
else:
|
||||||
print(f"Error 404: path={self.path}")
|
print(f"Error 404: path={self.path}")
|
||||||
|
Loading…
Reference in New Issue
Block a user