fix: use SessionLocal instead of db in education guide route
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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-03-13 12:05:46 +01:00
parent ef125baf57
commit a1ea4f0b20

View File

@ -59,34 +59,38 @@ def index():
@login_required
def google_reviews_guide():
"""Poradnik o opiniach Google dla członków Izby."""
from database import db, CompanyWebsiteAnalysis, Company
from database import SessionLocal, CompanyWebsiteAnalysis, Company
# Get GBP data for the current user's company
gbp_data = None
company = None
if current_user.company_id:
company = db.session.get(Company, current_user.company_id)
if company:
analysis = (
db.session.query(CompanyWebsiteAnalysis)
.filter_by(company_id=company.id)
.order_by(CompanyWebsiteAnalysis.analyzed_at.desc())
.first()
)
if analysis and analysis.google_place_id:
links = analysis.google_maps_links or {}
gbp_data = {
'company_name': company.name,
'google_name': analysis.google_name,
'rating': float(analysis.google_rating) if analysis.google_rating else None,
'reviews_count': analysis.google_reviews_count or 0,
'photos_count': analysis.google_photos_count or 0,
'write_review_url': links.get('writeAReviewUri'),
'reviews_url': links.get('reviewsUri'),
'place_url': links.get('placeUri'),
'photos_url': links.get('photosUri'),
'google_maps_url': analysis.google_maps_url,
}
db = SessionLocal()
try:
company = db.get(Company, current_user.company_id)
if company:
analysis = (
db.query(CompanyWebsiteAnalysis)
.filter_by(company_id=company.id)
.order_by(CompanyWebsiteAnalysis.analyzed_at.desc())
.first()
)
if analysis and analysis.google_place_id:
links = analysis.google_maps_links or {}
gbp_data = {
'company_name': company.name,
'google_name': analysis.google_name,
'rating': float(analysis.google_rating) if analysis.google_rating else None,
'reviews_count': analysis.google_reviews_count or 0,
'photos_count': analysis.google_photos_count or 0,
'write_review_url': links.get('writeAReviewUri'),
'reviews_url': links.get('reviewsUri'),
'place_url': links.get('placeUri'),
'photos_url': links.get('photosUri'),
'google_maps_url': analysis.google_maps_url,
}
finally:
db.close()
return render_template('education/google_reviews_guide.html',
gbp_data=gbp_data, company=company)