fix: AI generation Company.city error, missing publishing_company_id, and UX error display
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
- Fix AttributeError: Company.city -> Company.address_city in get_company_context - Default publishing_company_id to first available company when not selected - Replace alert() with inline error message for AI generation failures - Return user-friendly error messages instead of internal exceptions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2e638b94dd
commit
c4036f0a62
@ -141,6 +141,10 @@ def social_publisher_new():
|
|||||||
event_id = request.form.get('event_id', type=int)
|
event_id = request.form.get('event_id', type=int)
|
||||||
publishing_company_id = request.form.get('publishing_company_id', type=int)
|
publishing_company_id = request.form.get('publishing_company_id', type=int)
|
||||||
|
|
||||||
|
# Default to first company if not selected
|
||||||
|
if not publishing_company_id and companies:
|
||||||
|
publishing_company_id = companies[0].id
|
||||||
|
|
||||||
if not content:
|
if not content:
|
||||||
flash('Treść posta jest wymagana.', 'danger')
|
flash('Treść posta jest wymagana.', 'danger')
|
||||||
return render_template('admin/social_publisher_form.html',
|
return render_template('admin/social_publisher_form.html',
|
||||||
@ -363,7 +367,7 @@ def social_publisher_generate():
|
|||||||
return jsonify({'success': True, 'content': content, 'model': model})
|
return jsonify({'success': True, 'content': content, 'model': model})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"AI generation failed: {e}")
|
logger.error(f"AI generation failed: {e}")
|
||||||
return jsonify({'success': False, 'error': str(e)}), 500
|
return jsonify({'success': False, 'error': 'Nie udalo sie wygenerowac tresci. Sprobuj ponownie lub wpisz tresc recznie.'}), 500
|
||||||
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|||||||
@ -420,7 +420,7 @@ class SocialPublisherService:
|
|||||||
return {
|
return {
|
||||||
'company_name': company.name or '',
|
'company_name': company.name or '',
|
||||||
'category': company.category or '',
|
'category': company.category or '',
|
||||||
'city': company.city or 'Wejherowo',
|
'city': company.address_city or 'Wejherowo',
|
||||||
'description': company.description or company.short_description or '',
|
'description': company.description or company.short_description or '',
|
||||||
'website': company.website or '',
|
'website': company.website or '',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -281,6 +281,7 @@
|
|||||||
Generuj AI
|
Generuj AI
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="ai-error-msg" style="display:none; padding: var(--spacing-sm) var(--spacing-md); margin-bottom: var(--spacing-md); border-radius: var(--radius); background: var(--error-bg, #fef2f2); color: var(--error, #dc2626); border: 1px solid var(--error, #dc2626); font-size: var(--font-size-sm);"></div>
|
||||||
|
|
||||||
<!-- Tresc -->
|
<!-- Tresc -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -362,6 +363,15 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
|
function showAiError(msg) {
|
||||||
|
const el = document.getElementById('ai-error-msg');
|
||||||
|
el.textContent = msg;
|
||||||
|
el.style.display = 'block';
|
||||||
|
}
|
||||||
|
function hideAiError() {
|
||||||
|
document.getElementById('ai-error-msg').style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
// AI generation
|
// AI generation
|
||||||
document.getElementById('btn-generate-ai')?.addEventListener('click', async function() {
|
document.getElementById('btn-generate-ai')?.addEventListener('click', async function() {
|
||||||
const postType = document.getElementById('post_type').value;
|
const postType = document.getElementById('post_type').value;
|
||||||
@ -407,11 +417,12 @@
|
|||||||
document.getElementById('hashtags').value = data.hashtags;
|
document.getElementById('hashtags').value = data.hashtags;
|
||||||
}
|
}
|
||||||
updateContentCounter();
|
updateContentCounter();
|
||||||
|
hideAiError();
|
||||||
} else {
|
} else {
|
||||||
alert('Błąd generowania: ' + (data.error || 'Nieznany błąd'));
|
showAiError(data.error || 'Nie udalo sie wygenerowac tresci. Sprobuj ponownie.');
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert('Błąd połączenia: ' + err.message);
|
showAiError('Blad polaczenia z serwerem. Sprawdz polaczenie internetowe i sprobuj ponownie.');
|
||||||
} finally {
|
} finally {
|
||||||
this.disabled = false;
|
this.disabled = false;
|
||||||
this.textContent = 'Generuj AI';
|
this.textContent = 'Generuj AI';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user