fix(company): convert uploaded logos to .webp so templates display them
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Templates expect logo at {slug}.webp with SVG fallback. When users uploaded
JPG/PNG files, the logo was saved with original extension and never displayed.
Now all raster uploads are converted to .webp via Pillow; SVG stays as-is.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9f052f5173
commit
bd179dec97
@ -237,12 +237,12 @@ def _save_description(db, company):
|
|||||||
else:
|
else:
|
||||||
company.category_id = None
|
company.category_id = None
|
||||||
|
|
||||||
# Logo upload — save as static/img/companies/{slug}.{ext}
|
# Logo upload — always convert to .webp (templates expect {slug}.webp)
|
||||||
# company_detail.html expects logo at this path with webp→svg fallback
|
|
||||||
logo_file = request.files.get('logo_file')
|
logo_file = request.files.get('logo_file')
|
||||||
if logo_file and logo_file.filename:
|
if logo_file and logo_file.filename:
|
||||||
import os
|
import os
|
||||||
from werkzeug.utils import secure_filename
|
from PIL import Image
|
||||||
|
import io
|
||||||
|
|
||||||
allowed = {'png', 'jpg', 'jpeg', 'svg', 'webp'}
|
allowed = {'png', 'jpg', 'jpeg', 'svg', 'webp'}
|
||||||
ext = logo_file.filename.rsplit('.', 1)[-1].lower() if '.' in logo_file.filename else ''
|
ext = logo_file.filename.rsplit('.', 1)[-1].lower() if '.' in logo_file.filename else ''
|
||||||
@ -254,8 +254,14 @@ def _save_description(db, company):
|
|||||||
old_path = os.path.join(logo_dir, f"{company.slug}.{old_ext}")
|
old_path = os.path.join(logo_dir, f"{company.slug}.{old_ext}")
|
||||||
if os.path.exists(old_path):
|
if os.path.exists(old_path):
|
||||||
os.remove(old_path)
|
os.remove(old_path)
|
||||||
filepath = os.path.join(logo_dir, f"{company.slug}.{ext}")
|
filepath = os.path.join(logo_dir, f"{company.slug}.webp")
|
||||||
logo_file.save(filepath)
|
if ext == 'svg':
|
||||||
|
# SVG stays as-is (can't convert to webp)
|
||||||
|
filepath = os.path.join(logo_dir, f"{company.slug}.svg")
|
||||||
|
logo_file.save(filepath)
|
||||||
|
else:
|
||||||
|
img = Image.open(logo_file)
|
||||||
|
img.save(filepath, 'WEBP', quality=85)
|
||||||
logger.info(f"Logo uploaded for company {company.id}: {filepath}")
|
logger.info(f"Logo uploaded for company {company.id}: {filepath}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user