style: Enhance team member photo handling and ensure fallback members are displayed when no team members are available

This commit is contained in:
2026-05-11 14:57:03 +02:00
parent 0d2fbebb82
commit f74866600d
2 changed files with 16 additions and 3 deletions
+9 -1
View File
@@ -126,8 +126,16 @@ def _save_team_photo(file_obj, identifier: str) -> str | None:
if not _is_allowed_image_filename(original_name):
return None
os.makedirs(TEAM_UPLOAD_DIR, exist_ok=True)
extension = os.path.splitext(original_name)[1].lower() or ".jpg"
# If a photo for this identifier already exists, keep the first one and return it.
safe_identifier = secure_filename(identifier or "member")
try:
for existing in sorted(os.listdir(TEAM_UPLOAD_DIR)):
if existing.startswith(f"team_{safe_identifier}_"):
return f"uploads/team/{existing}"
except Exception:
# If listing fails for any reason, proceed to save new file.
pass
extension = os.path.splitext(original_name)[1].lower() or ".jpg"
unique_name = f"team_{safe_identifier}_{datetime.utcnow().strftime('%Y%m%d%H%M%S')}{extension}"
target = os.path.join(TEAM_UPLOAD_DIR, unique_name)
file_obj.save(target)