From 1324d93b8094538595f33df417ee13a042b18e29 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 20 Dec 2022 14:56:52 -0300 Subject: [PATCH] Fix: acces photo sans photos ni portail --- app/scodoc/sco_photos.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index c0f3cbd8..37908d51 100644 --- a/app/scodoc/sco_photos.py +++ b/app/scodoc/sco_photos.py @@ -73,7 +73,7 @@ from config import Config PHOTO_DIR = os.path.join(Config.SCODOC_VAR_DIR, "photos") ICONS_DIR = os.path.join(Config.SCODOC_DIR, "app", "static", "icons") UNKNOWN_IMAGE_PATH = os.path.join(ICONS_DIR, "unknown.jpg") -UNKNOWN_IMAGE_URL = "get_photo_image?etudid=" # with empty etudid => unknown face image + IMAGE_EXT = ".jpg" JPG_QUALITY = 0.92 REDUCED_HEIGHT = 90 # pixels @@ -81,6 +81,11 @@ MAX_FILE_SIZE = 4 * 1024 * 1024 # max allowed size for uploaded image, in bytes H90 = ".h90" # suffix for reduced size images +def unknown_image_url() -> str: + "URL for 'unkwown' face image" + return url_for("scolar.get_photo_image", scodoc_dept=g.scodoc_dept, etudid="") + + def photo_portal_url(etud): """Returns external URL to retreive photo on portal, or None if no portal configured""" @@ -118,7 +123,7 @@ def etud_photo_url(etud: dict, size="small", fast=False) -> str: ext_url = photo_portal_url(etud) if not ext_url: # fallback: Photo "unknown" - photo_url = scu.ScoURL() + "/" + UNKNOWN_IMAGE_URL + photo_url = unknown_image_url() else: # essaie de copier la photo du portail new_path, _ = copy_portal_photo_to_fs(etud) @@ -128,7 +133,7 @@ def etud_photo_url(etud: dict, size="small", fast=False) -> str: if scu.CONFIG.PUBLISH_PORTAL_PHOTO_URL: photo_url = ext_url else: - photo_url = scu.ScoURL() + "/" + UNKNOWN_IMAGE_URL + photo_url = unknown_image_url() return photo_url @@ -143,7 +148,8 @@ def get_photo_image(etudid=None, size="small"): filename = photo_pathname(etud.photo_filename, size=size) if not filename: filename = UNKNOWN_IMAGE_PATH - return _http_jpeg_file(filename) + r = _http_jpeg_file(filename) + return r def _http_jpeg_file(filename): @@ -166,7 +172,7 @@ def _http_jpeg_file(filename): except ValueError: mod_since = None if (mod_since is not None) and last_modified <= mod_since: - return "", 304 # not modified + return make_response(b"", 304) # not modified # last_modified_str = time.strftime( "%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last_modified) @@ -183,7 +189,7 @@ def etud_photo_is_local(etud: dict, size="small"): return photo_pathname(etud["photo_filename"], size=size) -def etud_photo_html(etud: dict = None, etudid=None, title=None, size="small"): +def etud_photo_html(etud: dict = None, etudid=None, title=None, size="small") -> str: """HTML img tag for the photo, either in small size (h90) or original size (size=="orig") """ @@ -201,7 +207,7 @@ def etud_photo_html(etud: dict = None, etudid=None, title=None, size="small"): title = nom if not etud_photo_is_local(etud): fallback = ( - """onerror='this.onerror = null; this.src="%s"'""" % UNKNOWN_IMAGE_URL + f"""onerror='this.onerror = null; this.src="{unknown_image_url()}"'""" ) else: fallback = "" @@ -218,7 +224,7 @@ def etud_photo_html(etud: dict = None, etudid=None, title=None, size="small"): ) -def etud_photo_orig_html(etud=None, etudid=None, title=None): +def etud_photo_orig_html(etud=None, etudid=None, title=None) -> str: """HTML img tag for the photo, in full size. Full-size images are always stored locally in the filesystem. They are the original uploaded images, converted in jpeg.