fix(company): fix logo upload saving to boolean column instead of file
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
Logo upload in company edit was writing the file path to `logo_dark_bg`
(a Boolean column), causing TypeError and rolling back ALL profile changes.
Now saves to static/img/companies/{slug}.{ext} where company_detail expects it.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cbb08cec60
commit
10eec63c2f
@ -237,7 +237,8 @@ def _save_description(db, company):
|
|||||||
else:
|
else:
|
||||||
company.category_id = None
|
company.category_id = None
|
||||||
|
|
||||||
# Logo upload
|
# Logo upload — save as static/img/companies/{slug}.{ext}
|
||||||
|
# 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
|
||||||
@ -246,12 +247,15 @@ def _save_description(db, company):
|
|||||||
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 ''
|
||||||
if ext in allowed:
|
if ext in allowed:
|
||||||
filename = secure_filename(f"company_{company.id}_logo.{ext}")
|
logo_dir = os.path.join('static', 'img', 'companies')
|
||||||
upload_dir = os.path.join('static', 'uploads', 'logos')
|
os.makedirs(logo_dir, exist_ok=True)
|
||||||
os.makedirs(upload_dir, exist_ok=True)
|
# Remove old logo files for this company (different extensions)
|
||||||
filepath = os.path.join(upload_dir, filename)
|
for old_ext in allowed:
|
||||||
|
old_path = os.path.join(logo_dir, f"{company.slug}.{old_ext}")
|
||||||
|
if os.path.exists(old_path):
|
||||||
|
os.remove(old_path)
|
||||||
|
filepath = os.path.join(logo_dir, f"{company.slug}.{ext}")
|
||||||
logo_file.save(filepath)
|
logo_file.save(filepath)
|
||||||
company.logo_dark_bg = os.path.join('uploads', 'logos', filename)
|
|
||||||
logger.info(f"Logo uploaded for company {company.id}: {filepath}")
|
logger.info(f"Logo uploaded for company {company.id}: {filepath}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -841,15 +841,11 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label">Logo firmy</label>
|
<label class="form-label">Logo firmy</label>
|
||||||
<div style="display: flex; align-items: center; gap: 16px; margin-bottom: 8px;">
|
<div style="display: flex; align-items: center; gap: 16px; margin-bottom: 8px;">
|
||||||
{% if company.logo_dark_bg %}
|
<div id="logoPreview" style="width: 80px; height: 80px; border-radius: 8px; border: 1px solid var(--border, #e0e4eb); overflow: hidden; display: flex; align-items: center; justify-content: center; background: #fff;">
|
||||||
<div style="width: 80px; height: 80px; border-radius: 8px; border: 1px solid var(--border, #e0e4eb); overflow: hidden; display: flex; align-items: center; justify-content: center; background: #fff;">
|
<img src="{{ url_for('static', filename='img/companies/' ~ company.slug ~ '.webp') }}" alt="Logo"
|
||||||
<img src="{{ url_for('static', filename=company.logo_dark_bg) }}" alt="Logo" style="max-width: 100%; max-height: 100%; object-fit: contain;">
|
style="max-width: 100%; max-height: 100%; object-fit: contain;"
|
||||||
|
onerror="if(!this.dataset.triedSvg){this.dataset.triedSvg='1';this.src=this.src.replace('.webp','.svg')}else{this.parentElement.innerHTML='<span style=\'color:var(--text-secondary,#999);font-size:12px\'>Brak logo</span>'}">
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
|
||||||
<div style="width: 80px; height: 80px; border-radius: 8px; border: 2px dashed var(--border, #e0e4eb); display: flex; align-items: center; justify-content: center; color: var(--text-secondary, #999); font-size: 12px; text-align: center;">
|
|
||||||
Brak logo
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div style="flex: 1;">
|
<div style="flex: 1;">
|
||||||
<input type="file" id="logo_file" name="logo_file" accept="image/png,image/jpeg,image/svg+xml,image/webp" class="form-input" style="padding: 8px;">
|
<input type="file" id="logo_file" name="logo_file" accept="image/png,image/jpeg,image/svg+xml,image/webp" class="form-input" style="padding: 8px;">
|
||||||
<p class="form-help" style="margin-top: 4px;">PNG, JPG, SVG lub WebP. Zalecany rozmiar: min. 200x200px.</p>
|
<p class="form-help" style="margin-top: 4px;">PNG, JPG, SVG lub WebP. Zalecany rozmiar: min. 200x200px.</p>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user