Fix: acces photo sans photos ni portail
This commit is contained in:
parent
66ebb77f30
commit
1324d93b80
@ -73,7 +73,7 @@ from config import Config
|
|||||||
PHOTO_DIR = os.path.join(Config.SCODOC_VAR_DIR, "photos")
|
PHOTO_DIR = os.path.join(Config.SCODOC_VAR_DIR, "photos")
|
||||||
ICONS_DIR = os.path.join(Config.SCODOC_DIR, "app", "static", "icons")
|
ICONS_DIR = os.path.join(Config.SCODOC_DIR, "app", "static", "icons")
|
||||||
UNKNOWN_IMAGE_PATH = os.path.join(ICONS_DIR, "unknown.jpg")
|
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"
|
IMAGE_EXT = ".jpg"
|
||||||
JPG_QUALITY = 0.92
|
JPG_QUALITY = 0.92
|
||||||
REDUCED_HEIGHT = 90 # pixels
|
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
|
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):
|
def photo_portal_url(etud):
|
||||||
"""Returns external URL to retreive photo on portal,
|
"""Returns external URL to retreive photo on portal,
|
||||||
or None if no portal configured"""
|
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)
|
ext_url = photo_portal_url(etud)
|
||||||
if not ext_url:
|
if not ext_url:
|
||||||
# fallback: Photo "unknown"
|
# fallback: Photo "unknown"
|
||||||
photo_url = scu.ScoURL() + "/" + UNKNOWN_IMAGE_URL
|
photo_url = unknown_image_url()
|
||||||
else:
|
else:
|
||||||
# essaie de copier la photo du portail
|
# essaie de copier la photo du portail
|
||||||
new_path, _ = copy_portal_photo_to_fs(etud)
|
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:
|
if scu.CONFIG.PUBLISH_PORTAL_PHOTO_URL:
|
||||||
photo_url = ext_url
|
photo_url = ext_url
|
||||||
else:
|
else:
|
||||||
photo_url = scu.ScoURL() + "/" + UNKNOWN_IMAGE_URL
|
photo_url = unknown_image_url()
|
||||||
return photo_url
|
return photo_url
|
||||||
|
|
||||||
|
|
||||||
@ -143,7 +148,8 @@ def get_photo_image(etudid=None, size="small"):
|
|||||||
filename = photo_pathname(etud.photo_filename, size=size)
|
filename = photo_pathname(etud.photo_filename, size=size)
|
||||||
if not filename:
|
if not filename:
|
||||||
filename = UNKNOWN_IMAGE_PATH
|
filename = UNKNOWN_IMAGE_PATH
|
||||||
return _http_jpeg_file(filename)
|
r = _http_jpeg_file(filename)
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
def _http_jpeg_file(filename):
|
def _http_jpeg_file(filename):
|
||||||
@ -166,7 +172,7 @@ def _http_jpeg_file(filename):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
mod_since = None
|
mod_since = None
|
||||||
if (mod_since is not None) and last_modified <= mod_since:
|
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(
|
last_modified_str = time.strftime(
|
||||||
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last_modified)
|
"%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)
|
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)
|
"""HTML img tag for the photo, either in small size (h90)
|
||||||
or original size (size=="orig")
|
or original size (size=="orig")
|
||||||
"""
|
"""
|
||||||
@ -201,7 +207,7 @@ def etud_photo_html(etud: dict = None, etudid=None, title=None, size="small"):
|
|||||||
title = nom
|
title = nom
|
||||||
if not etud_photo_is_local(etud):
|
if not etud_photo_is_local(etud):
|
||||||
fallback = (
|
fallback = (
|
||||||
"""onerror='this.onerror = null; this.src="%s"'""" % UNKNOWN_IMAGE_URL
|
f"""onerror='this.onerror = null; this.src="{unknown_image_url()}"'"""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
fallback = ""
|
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.
|
"""HTML img tag for the photo, in full size.
|
||||||
Full-size images are always stored locally in the filesystem.
|
Full-size images are always stored locally in the filesystem.
|
||||||
They are the original uploaded images, converted in jpeg.
|
They are the original uploaded images, converted in jpeg.
|
||||||
|
Loading…
Reference in New Issue
Block a user